problems parsing typedefed names

Rudy Wortel rudy at alias.UUCP
Tue Dec 12 13:51:56 AEST 1989


Consider the following C fragment:

/********************************/

typedef int definedtype;

float	definedtype[ 13 ];

typedef struct {
	float	definedtype[ 13 ];
} foo;

typedef struct {
	float	int[ 13 ];
} bar;

/********************************/

When i compiled this the compiler had this to say:

	cc -O -c frag.c
ccom: Error: frag.c, line 3: illegal type combination
      float	definedtype[ 13 ];
      ---------------------^
ccom: Error: frag.c, line 3: syntax error
      float	definedtype[ 13 ];
      ---------------------^
ccom: Error: frag.c, line 10: illegal type combination
      	float	int[ 13 ];
      -------------^
ccom: Error: frag.c, line 10: syntax error
      	float	int[ 13 ];
      -------------^
ccom: Error: frag.c, line 11: zero sized structure
      } bar;
      ^

My question is why does the compiler treat the the declarations with
'definedtype' differently when it is inside the structure definition?
If the use of 'definedtype[ 13 ]' is ok inside the structure then why
is the similar use of 'int[ 13 ]' not allowed?

The reason i am asking these apparently silly questions is that wrote a
C parser a while ago and could not get it to deal with the situation as
described above. It dealt with the two structure definitions similarly
by flagging syntax errors for both of them. i recently obtained an ansi
C grammar as advertized over the net ie:

	uunet.uu.net:~ftp/net.sources/ansi.c.grammar.Z

Thinking that it would deal with this problem and i could see what a
dummy i have been. But, it too does not allow the use of 'definedtype[ 13 ]'
in either definition. So, how does the compiler do it??? i have been
using the compiler on SGI 4Ds and 3000s, suns and a celerity which all
complain similarly.

For my CND$0.02 worth i consider any use of a type name, be it int or a
typedefed name, other than where a type is required, bad coding style
etc.:-( And not only that, i wouldn't do it even if i could get my parser
to handle it :-).

Since some of the code that i want to parse has this awfull stuff in it
any pointers as to how to deal with this would be appreciated.

Thanks for reading this far.

-------------------------------------------------------------------------------
Rudy Wortel                   O    o   O  o  O   o O oo oOoo ooOOoOoooo
Alias Research Inc.,              o         O  OOo    O    ooOO OOo ooOOOOo
110 Richmond St. E.,          o                                            O
Toronto Ontario,                         _[#]_t____   ___xxxx ===__m_n__n__H_
Canada. M5C 1P1                         :_|>)____|_:_(___[__]_[#]____________P
rudy%alias at utcsri.utoronto.ca ___________o-o    o-o  ooo  ooo o-o O-O-O-O o-o\



More information about the Comp.lang.c mailing list