Re: ISO: help porting C code to 64 bit linux platform



Måns Rullgård wrote:

That is a good example of how *not* to write code. *Never*, ever read
or write a struct directly to/from a file. The compiler is free to
insert padding wherever it likes in a struct.

Somehow, I feel you are both right... but you didn't set properly your
initial conditions.

I think that this is true to FORCE variables size when the data are
coming from outside the program. Typically, in the example of Julián the
struct describe the structure of a wav file which should be played on
any type of machine. This is clearly some data imported from outside the
software and on which the programmer has no control.

On the other hand, Måns is right for all the variables which are lying
within the program. It should be define as a coherent data flow without
relying on the size of it.

At last, variables which are exported outside of the software must also
have a known size ('cause they will be imported at some other point).

That's all folks !
--
Emmanuel Fleury | Office: 261
Associate Professor, | Phone: +33 (0)5 40 00 69 34
LaBRI, Domaine Universitaire | Fax: +33 (0)5 40 00 66 69
351, Cours de la Libération | email: emmanuel.fleury@xxxxxxxx
33405 Talence Cedex, France | URL: http://www.labri.fr/~fleury
.



Relevant Pages

  • Re: Array assignment via struct
    ... >>> the DS9000 is the only implementation to include padding. ... >> No, it isn't a pedantic point, there are many systems where a struct is ... even a compiler which generates memcpy(or its ...
    (comp.lang.c)
  • Re: Read binary data file
    ... of padding which is used internally within a struct is undefined by the ... language - it is entirely up to the compiler developer. ... If you write a struct ... were writing into their binary files. ...
    (comp.lang.java.programmer)
  • Re: komplexes Problem mit Funktionszeigern
    ... Die Funktion gibt einen struct "by value" zurueck und bei der ... am Borland Compiler, da der Microsoft Compiler ... Man kann Argumente fuer eine Funktion z.B auf dem Stack uebergeben. ... Das funktioniert natuerlich nur fuer "Basis Typen" die in ein Register passen. ...
    (de.comp.lang.c)
  • Re: Structure Packing.
    ... would it ever be acceptable for a compiler to align var2 on a 4/8 byte boundary, for speed, architectural or indeed any reason. ... there will be no padding between them. ... two struct members, ...
    (comp.std.c)
  • Re: Replace bcopy() to update ether_addr
    ... Good for source code ugliness and bloat (not just in the macro). ... reduces to a struct copy if the object being copy is a struct, ... It has the side effect of allowing the compiler to not ... have more than byte alignment. ...
    (freebsd-hackers)