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

On 2007-01-13, Jan Panteltje <pNaonStpealmtje@xxxxxxxxx> wrote:
On a sunny day (Fri, 12 Jan 2007 19:25:08 +0000) it happened
=?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= <mru@xxxxxxxxxxxxx> wrote in

Emmanuel Fleury <emmanuel.fleury@xxxxxxxx> writes:

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.

I have to still see that happen in gcc, do you have a code example?

#include <stdint.h>

struct foo
int64_t a;
char b;
return sizeof(struct foo);

on pentium (32 bit) gcc this return 12
on avr (8 bit) gcc this returns 9
on a 64 bit gcc it'll probably 16

if you can't how the above implies padding consider an array of struct foo.

The WAV header has a number of fixed-size fields, that is true.
However, that does not imply that the variables used to hold these
values inside a program need to have the same size. They need to be
at least as wide, but it doesn't hurt if they are wider if that makes
for more efficient code.

Will create problems too, as then when you write the header back, it may overflow.
(You cannot put a 64 bit value into a 32 bit register).
For exampe in a program that concatenates n wave files, the resulting could easily be > 4GB.
That would require a check and error abort (but you would need that anyways).

any problems encountered there would not have been avoided by using shorter
variables in the main program.