Writing Shared Libraries, first draft
Scott James Remnant
scott at netsplit.com
Mon Nov 8 14:17:34 EET 2004
On Mon, 2004-11-08 at 11:03 +0000, Mike Hearn wrote:
> Alexander Larsson wrote:
> > No. This is bad. It'll allow less functions to be added on arches with
> > 64bit function pointers than on 32bit, thus making half the allocated
> > padding space useless.
>
> So using function pointers as padding is the correct thing to do then?
>
> Is there any way to pad structures that is "correct" at all?
>
No, the right thing to do is to make sure your API doesn't rely on the
size of the structure. A common trick is:
typedef struct _secret_struct SecretStruct;
and then use "SecretStruct *" everywhere, for all function calls, return
values, etc.
You then only flesh out "struct _secret_struct" inside the C file itself
so its contents and size aren't available as part of your API. Any
attempt outside of that C file to use the structure as anything but a
pointer will result in an error that the size of the structure is not
known.
You can freely increase the size of this structure knowing that it can't
break anything, because nothing knew the original size.
Scott
--
Have you ever, ever felt like this?
Had strange things happen? Are you going round the twist?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/xdg/attachments/20041108/20c39bc3/attachment.pgp
More information about the xdg
mailing list