[wplug] C compiling question

Bob Schmertz rschmertz at speakeasy.net
Tue Oct 1 01:23:03 EDT 2002


On Tue, 2002-10-01 at 00:03, James O'Kane wrote:
> Did something like this ever work as expected with any version of gcc? I
> found this code in mod_throttle, an apache module to add quotas to remote
> users. I'm surprised that it is being distributed because at least for me,
> it doesn't do what I would want. I've changed things to strcmp(), so I'm
> all set in terms of getting it to work, but I'm curious if gcc ever
> compiled this so it would work?
> 
> 
> static const char true[] = "true";
> char *foo = NULL;
> 
> foo = setfoo();
> 
> if(foo == true){
> // do stuff if foo is true
> }

Well, this comparison compares the pointer values, so it will only be
true if foo is pointing to the variable true itself. (Hard to discuss
this, can't put the variable name in quotes, because then it looks like
a string literal rather than a reference to the variable, etc.)  You
don't tell us what setfoo() does.  If it does something like:

char * setfoo() {
	char t[5] = "true";
	return t;
}

...wherein it creates a character array that contains the letters 't',
'r', 'u', 'e', '\0', then your if condition will never pass.

If foo and true were C++ objects, that would be a different story.

I suspect I've totally misunderstood what you're asking, but oh, well :)

-- 
Cheers,
Bob Schmertz



More information about the wplug mailing list