This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
anonymous types
- To: gcc-bugs at gcc dot gnu dot org
- Subject: anonymous types
- From: "Mark M. Young" <youngmm at hera dot wku dot edu>
- Date: Thu, 4 May 2000 08:35:10 -0500 (CDT)
Hopefully I won't get thrashed like I did the last time...
Why does GNU C/C++ allow my "anonymous struct" to be declared, but not
passed as a parameter? This error is from the attached file when I try to
use the 'struct' defined in the '#else' section after the '#ifdef
__GNUC__' section. The section that is not allowed is practical identical
to the section allowed except that the struct is given a name. What does
that matter? I don't see why it should complain.
non-local function `datatype func(const {anonymous struct} (&)[2][3])'
uses anonymous type
When I ask people these questions, they always spout off the
standard--where the crap do I find it?
Mark M. Young
youngmm@hera.wku.edu
note: A friend of mine's name is Shannon Johnson. That is why the example
code is laced with those two words.
"Do those sticks on the board mean bitwise or, absolute value,
matrix determinant, UNI* I/O redirection, the letter 'l',
the letter 'I', the number '1', or stray marks?"
--anonymous computer science student in response to "sticks" on a chalkboard
36 24 36...
#ifdef __GNUC__
# include <iostream>
# include <climits>
#else // #ifdef __GNUC__
# include <iostream.h>
# include <limits.h>
#endif // #ifdef __GNUC__
enum { ROWS = 2, COLS = 3 };
typedef unsigned long datatype;
#ifdef __GNUC__
typedef struct representation
{
datatype member;
} representation;
typedef representation example[ ROWS ][ COLS ];
#else // #ifdef __GNUC__
typedef struct
{
datatype member;
} example[ ROWS ][ COLS ];
#endif // #ifdef __GNUC__
datatype func( const example& johnson );
int main( int argc, char *argv[] )
{
example shannon;
shannon[ 0 ][ 0 ].member = ULONG_MAX;
// thought you'd appreciate the incidental humor
cout << func( shannon ) << endl;
return 0;
}
datatype func( const example& johnson )
{ return johnson[ 0 ][ 0 ].member; }