DEVELOP > c-Plus-Plus > Re: sizeof() , different results for same thing in C and C++. Why?
| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Tristan Wibberley" |
| Date: |
10 Jan 2008 01:27:50 PM |
| Object: |
Re: sizeof() , different results for same thing in C and C++. Why? |
On Thu, 2008-01-10 at 20:21 +0100, Rolf Magnus wrote:
In C, empty structs are not allowed. AFAICS, the program is ill-formed.
Then it's undefined behaviour and there is no problem with the C program
outputting 0.
--
Tristan Wibberley
Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.
.
|
|
| User: "Jack Klein" |
|
| Title: Re: sizeof() , different results for same thing in C and C++. Why? |
10 Jan 2008 09:33:05 PM |
|
|
On Thu, 10 Jan 2008 19:27:50 GMT, Tristan Wibberley
<maihem-nn1@maihem.org> wrote in comp.lang.c++:
On Thu, 2008-01-10 at 20:21 +0100, Rolf Magnus wrote:
In C, empty structs are not allowed. AFAICS, the program is ill-formed.
Then it's undefined behaviour and there is no problem with the C program
outputting 0.
Not quite, it violates the grammar and thus requires a diagnostic. If
an executable is produced along with the diagnostic, the result is not
a C program so even the C term of "undefined behavior" does not really
apply.
No diagnostic means not compiled with a conforming C compiler, which
most compilers, not just gcc, are not by default.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.
|
|
|
|
| User: "Default User" |
|
| Title: Re: sizeof() , different results for same thing in C and C++. Why? |
10 Jan 2008 02:15:45 PM |
|
|
Tristan Wibberley wrote:
On Thu, 2008-01-10 at 20:21 +0100, Rolf Magnus wrote:
In C, empty structs are not allowed. AFAICS, the program is
ill-formed.
Then it's undefined behaviour and there is no problem with the C
program outputting 0.
I don't think so. I believe it is a constraint violation that requires
a diagnostic. As I mentioned elsewhere, VC++ 6.0 does issue one.
Brian
.
|
|
|
|

|
Related Articles |
|
|