PSkocik PSkocik - 1 year ago 59
C Question

Will a void* always have the same representation as a char*?

Will a

always have the same representation as a


I want to work with a variadic function that takes char*'s terminated by a
like so:

int variadic(char*, ...); //<-prototype
variadic("foo", "bar", (char*)0); //<- usage

I wanted to replace
, but judging from's:

66) The macro NULL is defined in (and other headers) as a
null pointer constant; see 7.19.

3 An integer constant expression with the value 0, or such an
expression cast to type void *, is called a null pointer constant. 66)
If a null pointer constant is converted to a pointer type, the
resulting pointer, called a null pointer, is guaranteed to compare
unequal to a pointer to any object or function.

I can't, because in the
context, I absolutely need a
and a plain
is unacceptable.

If I defined:

#define NIL (void*)0 /*<= never a plain 0*/

would it be legal for me to use it to terminate my

Answer Source

It's specifically allowed to access a void* argument using va_arg(args, char*) and vice versa, not just for the null pointer.

See also

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download