Problem with functions returning structs
Ernst Boetsch
boetsch at lan.informatik.tu-muenchen.dbp.de
Mon Sep 25 21:53:00 AEST 1989
Subject: Problem with functions returning structs
[ Sorry if this problem has already been reported ]
Hello,
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.
If I change the code conforming to the declaration
datum *fetch(datum key);
^
(not obeying the manual; as if fetch returns a pointer to the struct)
the GNUcc executable works fine but not the native cc executable.
I have the analogous problem with the GNUcc compiled database package
and the program compiled with the native cc or GNUcc.
I managed the problem by compile options controlling
'#ifdef ... #else ... #endif'.
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)?
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}
More information about the Comp.unix.wizards
mailing list