Problem with functions returning structs

James Buster bitbug at lonewolf.sun.com
Wed Sep 27 05:40:57 AEST 1989


In article <816 at tuminfo1.lan.informatik.tu-muenchen.dbp.de> boetsch at lan.informatik.tu-muenchen.dbp.de (Ernst Boetsch) writes:
>I had (portability ?) problems with functions returning structs as
>result:
>On my VAXstation with ULTRIX 3.0 I use the dbm(3) database package
>which is compiled with the native cc.  dbm(3) uses the struct
>	   typedef struct {char *dptr; int dsize;} datum;
>and functions like
>	   datum fetch(datum key);
>	   datum nextkey(datum key);
>
>If I compile my program (which uses dbm(3)) also with the native cc all
>is fine.
>Compiling it with GNUcc leads to runtime errors.

[stuff deleted]

>Now my questions:
>- Is this behavior a portability problem (I think so)
>  or did I make a mistake
>  or does GNUcc generate wrong code?
>- What is the best (most portable) way to handle this problem if it is
>  a portability problem.
>- Is there a similar problem with structs as function parameters (in my
>  environment both GNUcc and the native cc handled structs as
>  parameters in the same way)?

Basically, GNU cc uses a different return mechanism for functions that
return structures. It is necessary to give the flag `-fpcc-struct-return'
when you desire to use the return mechanism of the native compiler.
This flag is documented in gcc.texinfo, which should be contained in the
GNU cc distribution you received.

>Thanks in advance.
>	   Ernst Boetsch
>
>Ernst N. Boetsch,  Inst. fuer Informatik, Technische Universitaet Muenchen
>	      Postfach 20 24 20,	  D-8000 Muenchen 2,  West Germany
>boetsch at infovax.informatik.tu-muenchen.dbp.de	     Tel: +49 89 2105 2385
>boetsch%infovax.informatik.tu-muenchen.dbp.de @ {relay.cs.net, unido.uucp}


--
--------------------------------------------
	     James Buster
	Mad Hacker Extraordinaire
       bitbug at lonewolf.ebay.sun.com
	 bitbug%lonewolf at sun.com
	 sun.com!lonewolf!bitbug
--------------------------------------------



More information about the Comp.lang.c mailing list