Question about incomplete structure tags 
Author Message
 Question about incomplete structure tags

Is the following legal ANSI C ?

struct stag;

int func(struct stag *sp);

struct stag {
  int si;
  int sj;

Quote:
};

struct stag;

int func(struct stag *sp)
{
  return sp->si;

Quote:
}

In particular what effect does the second "struct stag" have. This
example (distilled from the lucid emacs sources) is accepted by Sun's
"acc", the SGI C compiler and gcc but rejected by the HP compiler with the
error message `Redeclaration of tag "stag"'.

--

Delcam International PLC.       Tel:  +44 21 766 5544   Fax: +44 21 766 5511



Sat, 02 Mar 1996 21:26:32 GMT  
 Question about incomplete structure tags

Quote:

> Is the following legal ANSI C ?
> struct stag;
> int func(struct stag *sp);
> struct stag { int si; int sj; };
> struct stag;
> int func(struct stag *sp) { return sp->si; }
> In particular what effect does the second "struct stag" have. This
> example (distilled from the lucid emacs sources) is accepted by Sun's
> "acc", the SGI C compiler and gcc but rejected by the HP compiler with the
> error message `Redeclaration of tag "stag"'.

The HP compiler is wrong, and this code is strictly conforming.
Subclause 6.5.2.3 of the Standard explains the meaning of tags in the
various places they occur. In this particular case, the second "struct
tag;" redeclares the tag in the same scope, and has no other action. The
redefinition is benign, since it is covered by the special exclusion to
the constraints in subclause 6.5 - the author of the HP compiler has
presumably misunderstood the rules for tags (declaring the same
identifier twice is often not permitted).

--
Clive D.W. Feather     | Santa Cruz Operation    | If you lie to the compiler,

Phone: +44 923 816 344 | Hatters Lane, Watford   |   - Henry Spencer
Fax:   +44 923 817 688 | WD1 8YN, United Kingdom | <== * NOTE NEW INFORMATION *



Sat, 09 Mar 1996 00:13:23 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. structure type includes incomplete structure?

2. ServicedComponent's - structure and attribute tagging question

3. using incomplete structure types as opaque types

4. Typedef'ed Incomplete Structure Types and Their Use

5. Incomplete structure declarations as opaque data types

6. ? incomplete structures ?

7. Incomplete structure declarations: only within structs?

8. Incomplete structure declarations.

9. structure, union & enumeration tags

10. Structure tags

11. A switch structure with multiple tags

12. searching .ini file for [tag] and reading data following [tag]

 

 
Powered by phpBB® Forum Software