Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!apple!sun-barr!newstop!sun!bitbug
From: bitbug@lonewolf.sun.com (James Buster)
Newsgroups: comp.lang.c
Subject: Re: Problem with functions returning structs
Message-ID: 
Date: 26 Sep 89 19:40:57 GMT
References: <816@tuminfo1.lan.informatik.tu-muenchen.dbp.de>
Sender: news@sun.Eng.Sun.COM
Followup-To: comp.lang.c
Organization: Sun Microsystems Federal, Inc.
Lines: 49
In-reply-to: boetsch@lan.informatik.tu-muenchen.dbp.de's message of 25 Sep 89 11:53:00 GMT

In article <816@tuminfo1.lan.informatik.tu-muenchen.dbp.de> boetsch@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@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@lonewolf.ebay.sun.com
	 bitbug%lonewolf@sun.com
	 sun.com!lonewolf!bitbug
--------------------------------------------