anonymous struct 
Author Message
 anonymous struct

I would like to know what ANSI C has to say about the anonymous struct
used in the following declaration:

typedef union {
  int tag;
  struct {
    int i;
    int j;
  };
  struct {
    double x;
  };

Quote:
} anon_t;

In particular, is this standard C?  I have seen it used but can find no
references to this on the Web or in K&R, 2nd Edition.

Thanks in advance,

--
Steven Dirkse, Ph.D.    GAMS Development Corporation
1217 Potomac St. NW             Washington DC  20007
Voice: (202)342-0180              Fax: (202)342-0181

--



Tue, 22 Jan 2002 03:00:00 GMT  
 anonymous struct

Quote:

> I would like to know what ANSI C has to say about the anonymous struct
> used in the following declaration:
> typedef union {
>   int tag;
>   struct {
>     int i;
>     int j;
>   };
>   struct {
>     double x;
>   };
> } anon_t;
> In particular, is this standard C?  I have seen it used but can find no
> references to this on the Web or in K&R, 2nd Edition.

The C standard clearly allows this declaration,  The tagless structure
type cannot be referred to outside the declaration of which it is a
part.
--



Thu, 24 Jan 2002 03:00:00 GMT  
 anonymous struct

! > I would like to know what ANSI C has to say about the anonymous struct
! > used in the following declaration:
! > typedef union {
! >   int tag;
! >   struct {
! >     int i;
! >     int j;
! >   };
! >   struct {
! >     double x;
! >   };
! > } anon_t;
! > In particular, is this standard C?  I have seen it used but can find no
! > references to this on the Web or in K&R, 2nd Edition.
!
! The C standard clearly allows this declaration,  The tagless structure
! type cannot be referred to outside the declaration of which it is a
! part.

Doug is confused.  While the standard does allow a struct declaration
with no tag inside another struct as Doug says, it does *not* allow a
struct declaration without a following declarator

-Larry Jones

Life's a lot more fun when you're not responsible for your actions. -- Calvin
--



Tue, 05 Feb 2002 03:00:00 GMT  
 anonymous struct

Quote:

>> Doug is confused.  While the standard does allow a struct declaration
> with no tag inside another struct as Doug says, it does *not* allow a
> struct declaration without a following declarator

Sorry; I thought there were declarators (member names) there.

typedef union {
        int tag;
        struct {
                int i;
                int j;
        } s1;
        struct {
                double x;
        } s2;

Quote:
} anon_t;

...
anon_t u;
...
++u.s1.i;       // allowed
--



Sat, 16 Feb 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. tricky casting question with anonymous structs

2. anonymous structs and unions : legal?

3. Anonymous object ??

4. Anonymous union in VC++ 7

5. about "anonymous union" problem

6. anonymous methods

7. anonymous functions in c

8. A Jazzy NULL, and ctors for Anonymous Classes

9. Anonymous sub-structures and GCC

10. dereferencing anonymous pointers

11. Anonymous unions

12. Anonymous unions in C with gcc?

 

 
Powered by phpBB® Forum Software