* Anonymous structure return problem
@ 2003-03-09 20:23 Dimitry Golubovsky
2003-03-09 22:13 ` Daniel Jacobowitz
0 siblings, 1 reply; 2+ messages in thread
From: Dimitry Golubovsky @ 2003-03-09 20:23 UTC (permalink / raw)
To: gcc
Hi,
I am trying to compile the following with egcs 2.91.66 (came with some
Slackware a while ago):
static struct { int __errcode; int __result; } read_int(int fd)
{
struct { int __errcode; int __result; } ret;
return ret;
}
This is of course a dummy code (a template, so to speak), but the
problem is that it does not compile. I do not want to declare a typedef
for the function's return type, so I define an anonymous structure (the
function returns a structure, not a pointer). I am getting "incompatible
types in return" compiler error for the line containing "return ret"
statement. Why doesn't this work?
Types for ret and for the function are identical as declared.
I would like to avoid explicit declaration of structure type.
Someone also tested the code on gcc 3.2.1 with the same (unsuccessful)
result.
--
Dmitry M. Golubovsky
South Lyon, MI
--
*** Sent from linux-users@lugwash.org *** http://www.lugwash.org
to unsubscribe: `echo "unsubscribe" | mail linux-users-request@lugwash.org`
--
Dmitry M. Golubovsky
South Lyon, MI
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Anonymous structure return problem
2003-03-09 20:23 Anonymous structure return problem Dimitry Golubovsky
@ 2003-03-09 22:13 ` Daniel Jacobowitz
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2003-03-09 22:13 UTC (permalink / raw)
To: Dimitry Golubovsky; +Cc: gcc
On Sun, Mar 09, 2003 at 03:12:54PM -0500, Dimitry Golubovsky wrote:
> Hi,
>
>
> I am trying to compile the following with egcs 2.91.66 (came with some
> Slackware a while ago):
>
> static struct { int __errcode; int __result; } read_int(int fd)
> {
> struct { int __errcode; int __result; } ret;
> return ret;
> }
>
> This is of course a dummy code (a template, so to speak), but the
> problem is that it does not compile. I do not want to declare a typedef
> for the function's return type, so I define an anonymous structure (the
> function returns a structure, not a pointer). I am getting "incompatible
> types in return" compiler error for the line containing "return ret"
> statement. Why doesn't this work?
>
> Types for ret and for the function are identical as declared.
>
> I would like to avoid explicit declaration of structure type.
>
> Someone also tested the code on gcc 3.2.1 with the same (unsuccessful)
> result.
Two structures with the same contents are incompatible in C; you have
to name it, either as a typedef or as a named structure.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-03-09 20:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-09 20:23 Anonymous structure return problem Dimitry Golubovsky
2003-03-09 22:13 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).