public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@airs.com>
To: ernesto@ornl.gov
Cc: "Alex J. Dam" <alexjdam@gmail.com>, GCC-Help <gcc-help@gcc.gnu.org>
Subject: Re: Moving to AMD64 bit and porting issues
Date: Mon, 24 Oct 2005 19:02:00 -0000	[thread overview]
Message-ID: <m3wtk23fiq.fsf@gossamer.airs.com> (raw)
In-Reply-To: <1130150271.24804.69.camel@localhost.localdomain>

"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

  reply	other threads:[~2005-10-24 19:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-22  5:26 Ernest L. Williams Jr.
2005-10-24 10:24 ` Alex J. Dam
2005-10-24 10:33   ` random
2005-10-24 10:37   ` Ernest L. Williams Jr.
2005-10-24 19:02     ` Ian Lance Taylor [this message]
2005-11-04 11:54       ` Segher Boessenkool
2005-11-04 12:05         ` Ernest L. Williams Jr.
2005-11-04 12:35           ` Segher Boessenkool

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3wtk23fiq.fsf@gossamer.airs.com \
    --to=ian@airs.com \
    --cc=alexjdam@gmail.com \
    --cc=ernesto@ornl.gov \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).