This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
RE: Is a Pointer identical to a Struct { Pointer }?
- From: Jay K <jay dot krell at cornell dot edu>
- To: <marco dot devillers at gmail dot com>, <libffi-discuss at sourceware dot org>
- Date: Wed, 15 Dec 2010 03:29:22 +0000
- Subject: RE: Is a Pointer identical to a Struct { Pointer }?
- References: <AANLkTi=YieYwMvHhvEyqAZmh=XbH18LGMNWMzGtD70+F@mail.gmail.com>,<COL101-W331093B71ACB4DE7FFA6C6E6140@phx.gbl>
I believe the answer is that it depends on the ABI.
Some ABIs might sometimes enregister small structs, making the answer yes.
Some ABIs might never enregister small structs, making the answer no.
- Jay
> Date: Wed, 15 Dec 2010 02:58:23 +0100
> Subject: Is a Pointer identical to a Struct { Pointer }?
> From: marco.devillers@gmail.com
> To: libffi-discuss@sourceware.org
>
> Hi all,
>
> This is a bit of a weird question regarding a quick-and-dirty fix.
>
> In my language I use libffi extensively to interface with C. Since I
> want to support strings in the language I want to discriminate between
> pointers and pointers to characters in the libffi type information of
> C functions called.
>
> Now one quick-and-dirty hack I came up with is just wrapping a single
> pointer in a structure as an 'encoding' of a char pointer. That
> manner, I could discriminate between pointers and 'encoded' pointers
> to characters easily.Of course, I would like to push values in the
> normal manner to the C function called.
>
> Now that scheme only works if a structure containing one pointer is
> treated identically to a pointer in most calling conventions of GCC,
> MVC, etc. on most OSes.
>
> Is the latter true. I.e., is the same stack structure build for a
> pointer, or a structure just holding a pointer? Is there an easier
> manner to solve this?
>
> Any help appreciated,
> Marco