Topic: sizeof delete &std::nothrow


Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Sun, 4 Mar 2001 20:21:47 GMT
Raw View
James Dennett wrote:
>
> "James Kuyper Jr." wrote:
...
> > I believe it should be equivalent to 'sizeof void', an expression which
> > bothers me, but I couldn't find any rules that it violates. If it
> > violates no rules, then the only thing I could imagine it doing is
> > resulting in a value of 0.
>
> As void is an incomplete type, it doesn't have a size.  That's why
> you can't do pointer arithmetic on (void*) values, unless you're using
> gcc or some other compiler which extends things so that sizeof void is
> effectively 1.

I know; I tried to cancel the message shortly after I sent it, but it
apparantly got through anyway.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Anon" <spamme@lots.UCAR.EDU>
Date: Wed, 28 Feb 2001 22:23:09 GMT
Raw View
A number of people claimed in an earlier post that

sizeof delete &std::nothrow;

was illegal or caused undefined behavior. It's obviously very dopy but I
don't understand what in the Standard makes this statement a problem.
I believe it's syntactically correct and harmless since it has no effect
whatsoever. It works on my compiler at least :)

Could anyone please elaborate for my edification? Thank you.



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Ron Natalie <ron@spamcop.net>
Date: Thu, 1 Mar 2001 06:45:41 GMT
Raw View

Anon wrote:
>
> sizeof delete &std::nothrow;
>
> was illegal or caused undefined behavior. It's obviously very dopy but I
> don't understand what in the Standard makes this statement a problem.
> I believe it's syntactically correct and harmless since it has no effect
> whatsoever. It works on my compiler at least :)
>

The delete expression has type void.

void is an incomplete type.

sizeof requires a complete type.  5.3.3/1 : sizeof shall not be applied to
an expession that has function or incomlete type.

Thus this is what the standard says is "a diagnosable semantic rule" that
you are violating.  A diagnostic is required.  The compiler I have that's
handy says:

 Error:  Type "void" is incomplete.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Thu, 1 Mar 2001 18:16:30 GMT
Raw View
Anon wrote:
>
> A number of people claimed in an earlier post that
>
> sizeof delete &std::nothrow;
>
> was illegal or caused undefined behavior. It's obviously very dopy but I
> don't understand what in the Standard makes this statement a problem.
> I believe it's syntactically correct and harmless since it has no effect
> whatsoever. It works on my compiler at least :)
>
> Could anyone please elaborate for my edification? Thank you.

I believe it should be equivalent to 'sizeof void', an expression which
bothers me, but I couldn't find any rules that it violates. If it
violates no rules, then the only thing I could imagine it doing is
resulting in a value of 0.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: James Dennett <jdennett@acm.org>
Date: Sun, 4 Mar 2001 04:12:46 GMT
Raw View
"James Kuyper Jr." wrote:
>
> Anon wrote:
> >
> > A number of people claimed in an earlier post that
> >
> > sizeof delete &std::nothrow;
> >
> > was illegal or caused undefined behavior. It's obviously very dopy but I
> > don't understand what in the Standard makes this statement a problem.
> > I believe it's syntactically correct and harmless since it has no effect
> > whatsoever. It works on my compiler at least :)
> >
> > Could anyone please elaborate for my edification? Thank you.
>
> I believe it should be equivalent to 'sizeof void', an expression which
> bothers me, but I couldn't find any rules that it violates. If it
> violates no rules, then the only thing I could imagine it doing is
> resulting in a value of 0.

As void is an incomplete type, it doesn't have a size.  That's why
you can't do pointer arithmetic on (void*) values, unless you're using
gcc or some other compiler which extends things so that sizeof void is
effectively 1.

sizeof void should result in a compile-time error.

-- James Dennett

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]