* g++ and null pointers
@ 2004-08-24 16:27 Eljay Love-Jensen
2004-08-24 17:18 ` Falk Hueffner
0 siblings, 1 reply; 2+ messages in thread
From: Eljay Love-Jensen @ 2004-08-24 16:27 UTC (permalink / raw)
To: gcc-help
Hi everyone,
GCC 3.3.1 on Cygwin
When I compile this test.cpp source...
// g++ -Wno-long-long -pedantic -Wall -W -c test.cpp
#define NULL __null
int main()
{
void* p;
p = 0;
p = 0u;
p = 0ul;
p = 0ull;
p = 0l;
p = 0ll;
p = false;
// silly...
p = -0;
p = -0u;
p = -0ul;
p = -0ull;
p = -0l;
p = -0ll;
p = -false;
// my druthers...
p = NULL;
return 0;
}
...GCC is happy with all of these assignments.
Are they all supposed (ISO 14882) to be legit? Some of them surprised me.
The negated ones are just for fun. I didn't go completely crazy with the
cheese whiz, and put in "!!0" and "+0" and hexadecimal, and octal, and
various permutations of the [uUlL]* suffix.
Sincerely,
--Eljay
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: g++ and null pointers
2004-08-24 16:27 g++ and null pointers Eljay Love-Jensen
@ 2004-08-24 17:18 ` Falk Hueffner
0 siblings, 0 replies; 2+ messages in thread
From: Falk Hueffner @ 2004-08-24 17:18 UTC (permalink / raw)
To: Eljay Love-Jensen; +Cc: gcc-help
Eljay Love-Jensen <eljay@adobe.com> writes:
> When I compile this test.cpp source...
>
> // g++ -Wno-long-long -pedantic -Wall -W -c test.cpp
> #define NULL __null
> int main()
> {
> void* p;
> p = 0;
> p = 0u;
> p = 0ul;
> p = 0ull;
> p = 0l;
> p = 0ll;
> p = false;
> // silly...
> p = -0;
> p = -0u;
> p = -0ul;
> p = -0ull;
> p = -0l;
> p = -0ll;
> p = -false;
> // my druthers...
> p = NULL;
> return 0;
> }
>
> ...GCC is happy with all of these assignments.
>
> Are they all supposed (ISO 14882) to be legit? Some of them surprised me.
The standard says that a null pointer constant is "[a]n integer
constant expression with the value 0", so these seem all OK.
--
Falk
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-08-24 10:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-24 16:27 g++ and null pointers Eljay Love-Jensen
2004-08-24 17:18 ` Falk Hueffner
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).