Re: Returning structs
- From: jacob navia <jacob@xxxxxxxxxx>
- Date: Wed, 17 Dec 2008 07:48:15 +0100
Richard Heathfield wrote:
jacob navia said:
Jon Harrop wrote:James Kuyper wrote:Under linux, there is the gcc way, and there is no otherJon Harrop wrote:Only if I'm writing self-contained code. If I intend to expose anIs it ok to return structs from functions or are there ABIThe C standard requires that it be supported, it's up to the
issues?
implementation to do whatever it needs to do in the context of a
give ABI to make that happen. You don't have to worry about it.
API that includes functions returning structs then I need to know
this will be implemented consistently between compilers.
Just follow gcc and you will be OK.
Reasonably true, I think (BICBW).
Under windows there is the Microsoft way and there is no
other...
Well, what about Borland? OMF vs COFF and all that.
Just follow MSVC under windows and you will be OK.
...unless MSVC doesn't provide what you need. It's pretty good at Win32 API but pretty dreadful at RAD, which is why a lot of people do reach for Borland, and it's at this point (after they've already got a fair amount of MSVC code) that OMF vs COFF actually matters.
OMF is an old object file format. This means, it is a standard for
storing object files, organized in a linked list of variable size
records. The CONTENTS of those records, where the interface conventions
for returning structures is defined is completely another thing.
Obviously you can't link together a .lib (static library) of Borland
with Microsoft, since the object files differ.
In theory you *could* use a DLL linked by borland using a Microsoft
compiled program if the interfaces are the same.
But the best thing is to do as the windows API does: Do not return
structures by value but use a pointer to such a structure as an
argument.
Instead of
Mystruct function(int input1,int input2);
use:
int function(Mystruct *result,int input1,int input2);
Note that now you have the problem that the aligning of structure
members is important... Microsoft uses always
#pragma pack(1)
i.e. no alignment at all and uses structure layouts that minimize
problems of alignment in members.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
.
- Follow-Ups:
- Re: Returning structs
- From: Richard Heathfield
- Re: Returning structs
- References:
- Returning structs
- From: Jon Harrop
- Re: Returning structs
- From: James Kuyper
- Re: Returning structs
- From: Jon Harrop
- Re: Returning structs
- From: jacob navia
- Re: Returning structs
- From: Richard Heathfield
- Returning structs
- Prev by Date: Re: Returning structs
- Next by Date: Re: Returning structs
- Previous by thread: Re: Returning structs
- Next by thread: Re: Returning structs
- Index(es):
Relevant Pages
|