This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: error using "struct"


On Mon, Jul 07, 2003 at 06:11:14PM -0300, Fernanda Capella wrote:
> Hi!

Hi...
 
> I'm facing problems compilig a C program that uses struct. I made a very
> simple code to show the error: "parse error before '.' token".
> 
> Any help would be very appreciated.
> 
> Thanks, Fernanda.
> 
> 
> -------------------------------------------
> //struct_test.c
> 
> typedef struct struct_test{
>     unsigned char byte1;
>     unsigned char byte2;
>     unsigned char byte3;
> }first, second;
> 
> first.byte1=0x01;
> second.byte2=0x02;
> 
> ----------------------------------------------------
> //The error message:
> 
> [root@ root]# gcc -c struct_test.c
> struct_test.c:7: parse error before '.' token
> 

Your typedef just creates 2 aliases for your struct "struct_test"
called "first" and "second" ie "first" and "second" are no variables.

	first a;
	second a;
	struct struct_test a;

The above statements are semantically all equivalent. I suppose what
you're trying to do is the following:

	typedef struct struct_test {
	     unsigned char byte1;
	     unsigned char byte2;
	     unsigned char byte3; } struct_test;
	struct_test first, second;

-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux user                         - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]