[vorbis] Visual Studio .NET

Mercier, Dave dmercier at ea.com
Wed Apr 17 13:52:35 PDT 2002



> Does windows really not have a global, OS-wide struct packing convention?

I would think it's all compiler specific.

Dunno if this helps, but this is something I've run into and solved without
compiler or platform specific code (the exact same problem actually with 8
byte structure packing in VC). We solve it by making sure we pad out all our
public structures to at least 8 bytes. You might even want to go to 16 or
higher if that feels safer.

So our structs always look something like:

typedef struct EXAMPLE
{
        float32 value0;
        int16 value1;
        int16 value2;

        int32 value3;
        char8 value4;
        char8 pad[3];
} EXAMPLE;

So we've made sure EXAMPLE is padded out to 16 bytes. You just have to be
careful that you know the sizes of the types in your structure, and that
you've specified them in an order that makes sense.

Now in the library code, you can do something like this before you use any
structure, to ensure they are indeed padded correctly (things tend to change
over time and break if you don't test).

#define MIN_STRUCT_ALIGNMENT 8

assert(!(sizeof(EXAMPLE) % MIN_STRUCT_ALIGNMENT));

Maybe I'm missing something, but I would hope that would solve your
problems. It certainly solved mine across at least 10 platforms or so.

Thanks,
Dave.

<p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis mailing list