This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Moving to AMD64 bit and porting issues
"Ernest L. Williams Jr." <ernesto@ornl.gov> writes:
> Well, then what we are experiencing:
> 0 is an int and most likely 32 bits,
> NULL is a pointer and 64 bits in the 64-bit architecture.
>
>
> This then must be the problem, which makes using 0 to represent a NULL
> pointer not portable? Or would this be considered a bug with GCC for a
> 64-bit environment?
You can reliably use 0 as a null pointer constant with one exception.
When calling a varargs function which expects a pointer as an unnamed
argument, and when pointers are 64-bits but int is 32-bits, then you
must either use NULL or you must cast 0 to a pointer type.
For example:
char *
foo (int i, ...)
{
va_list va;
va_start (va, i);
char *p = va_arg (va, char *);
va_end (va);
return p;
}
char *bar () { return foo (1, 0); }
This will do the wrong thing if pointers are 64-bits. You must do
this instead:
char *bar () { return foo (1, (char *) 0); }
This is not a bug in gcc.
Ian