C
CBFalconer
Michael said:Umh, I am not sure what you mean. Maybe there is a
misunderstanding. Say, we have the following "program":
___________________________________________
#include <stdarg.h>
#include <stdio.h>
int foo (int is_intptr, void *ptr);
int bar (int howmany, ...);
int main (void)
{
int baz = 77;
printf("foo: %d\t", foo(1, &baz));
printf("baz: %d\n", baz);
return 0;
}
int foo (int is_intptr, void *ptr)
{
if (is_intptr)
return bar(1,(int *) ptr); /*<---*/
else
return -1;
}
int bar (int howmany, ...)
{
int m, *p;
va_list args;
va_start(args, howmany);
m = 0;
while (0 < howmany--) {
p = va_arg(args, int *);
m += *p - *p%42;
*p |= m;
}
va_end(args);
return m&0x42;
}
___________________________________________
Would you leave out the cast at the marked line in foo()?
If yes: What if the representations of (void *)&baz and
(int *)&baz were different?
No, but that is because bar is variadic, and ALL parameter values
have to be of the type expected. There is no parameter type here
to specify the conversion.
I guess I spoke too soon in respect to variadic functions. But not
with respect to properly prototyped normal functions. After
pointers, variadic functions are one of the largest sources of
error in C programming.