C
CBFalconer
Nate said:CBFalconer said:[email protected] said:It's part of a test and I'm stumped. There is a function
void foo(char **x)
The function signature is given and cannot be changed, so no passing
of other values. The test case involves defining this variable:
char *y[] = { /* bunch of stuff */ }
and calling
foo(y)
In the above, "bunch of stuff" is a series of triplets, two
strings followed by a null string (""). However, the last
triplet ends with an integer 0. This seems that it's supposed
to signify the end of the array. However, it appears to me that
0 is the same binary value as for the empty string (NUL, \0,
whatever). So in effect, one cannot test for it as a sentry
value because it's actually the same as the preceding triplets.
Maybe "bunch of stuff" is that, but y is not. y is an array of
pointers to char, and those pointers also point to char arrays
that are not writeable. The arrays are strings, with a '\0'
terminal char. The last string is an empty string, and is used
to mark the end of the array.
Now consider what foo is. It appears, from your definition, to
be a function that returns void (i.e. nothing). It also
requires a parameter, x, which is a pointer to a char pointer.
Combining those things, the call to foo(y) cannot possibly do
anything.
Um? Here are some possible definitions for foo that do things.
void foo(char **x) { x[3] = "Hi mom!"; }
void foo(char **x) { while (*x) puts(*x++); }
void foo(char **x) { errno = EDOOFUS; }
void foo(char **x) { longjmp(somewhere); }
void foo(char **x) { abort(); }
In other words you want to use globals and side-effects. I should
have specified further.