Binary I/O for Newbie

Ali Çehreli acehreli at yahoo.com
Mon Feb 27 11:56:50 PST 2012


On 02/27/2012 11:43 AM, Tobias Brandt wrote:

 >>> If you wrote to the file with a C++ program, then I guess the
 >>> compiler aligned the data so that the whole struct is 128 bytes
 >>> in size. Technically, the C++ compiler is allowed to do
 >>> anything short of changing the order of the struct fields.
 >
 >> That is correct for non-POD types. The C++ compiler must treat
 >> POD structs essentially as if they are C structs.
 >
 > Correct me if I'm wrong. But as far a I know the C standard also
 > allows arbitrary alignment.

You were correct. I somehow misread "short of changing the order" as 
meaning "even changing the order". But even then I wasn't entirely correct.

Just  found this thread:

   http://stackoverflow.com/q/281045

C guarantees that the members are not reordered, but C++ allows 
reordering by "The order of allocation of nonstatic data members 
separated by an access-specifier is unspecified (11.1)."

Ali



More information about the Digitalmars-d-learn mailing list