October 5th, 2013, 12:26 PM
C struct alignment across compilers and operating systems
I am working on extending an application that features a (rather old) plugin system. The plugin system is designed to work on x86 only, but support any and all compilers on windows, linux and also OSX.
My goals are now to
1) extend the plugin framework in a backwards compatible way
2) port it elegantly to x64
So far so good.
The plugin subsystem essentially exports a bunch of SDK function like this:
extern "C" CDECL int somefunc(int a, int b);
which can be used by the plugin, and expect the plugin to export some function in return.
When a struct is supposed to be send to the plugin, the syntax of the system goes like this:
so the struct isnt handed over via a pointer, but every field has to be requested individually!
extern "C" CDECL int RequestStructField(int field, int structhandle);
From what i can tell from the comments, the developer was afraid there might be problems exchanging structs between different compilers, alignment and all.
I would like to tear down this limitation, and pass pointers to structs to plugin directly. Or better: allow the plugin to give me a pointer to an empty struct which i subsequently fill.
However, i have no control over the compiler or language used to write the plugins. Quiet some plugins are written in Delphi, some even in MASM ... both would have to support this way of passing structs.
the question is: does that work?
I have looked at other plugin systems, but they either use entirely different ways (XPCOM) or are limited to a single platform or compiler.
Some of them have a note stating that the plugin must be compiled with "byte-aligned" structs.
Information is spare, though.
Any thoughts on this?
x86 and x64 plugins are two different stories, x64 version of the app does NOT have load x86 plugins.
I dont expect there to be too man problems (right?). But we'll see, i guess.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.