Re: sizeof() , different results for same thing in C and C++. Why?



 DEVELOP > c-Plus-Plus > Re: sizeof() , different results for same thing in C and C++. Why?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.


  Page 1 of 1

1

 


Related Articles
sizeof() , different results for same thing in C and C++. Why?
valarray.sum() gives unclean results
Dump program results to file
calling virtual function results in calling function of base class ...
find_if and mem_fun not getting expected results
Odd results with C++ under WinXP SP2
calling virtual function results in calling function of base class...
Strange Results with Overloaded Operators
Results of C++ Builder Programming Competition Posted
No results with MySQL
Unexpected results in matching a regex
New results in. What should I do? (was Re: Can I avoid the use ofarrays in this situation or do I have to use them?)
Specialisation of a template that results to another template
Prefix increment/decrement results in lvalue, but postfix one results in rvalue?
loop vs memset to initialize array.. different results?
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER