This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: New null_terminated attribute for C/C++


Tom Tromey <tromey@redhat.com> writes:

| >>>>> "Jason" == Jason Merrill <jason@redhat.com> writes:
| 
| Jason> This is inappropriate for C++, where NULL must have integral
| Jason> type.  Perhaps you could compare against null_pointer_node as
| Jason> well?
| 
| Isn't calling exec("foo", "bar", NULL) from C++ is an error, because
| NULL is 0?  Suppose sizeof(int)!=sizeof(char*).  Then the 0 will be
| the wrong width.  Or is NULL in C++ guaranteed to be a pointer-width 0?

NULL in g++ is defined to be __null which is of integral-type but
pointer-sized. So if you use NULL (as defined by g++) there should be
no problem; but if you use plain 0 then you're asking for trouble.

I understand Jason's comment as saying that you should not just
testing for integral type (which __null is) but also test for
null_pointer_node (which represents __null) and OK for that integral
constant expression since the obvious thing will happen.  That, IMO, is
a sensible way to go.

| I ran into this when debugging the patch.  Also I noticed, to my
| surprise, that if you do the above, the 0 argument is not null_pointer_node.
| It is some other 0-valued constant.

As it should.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]