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"


Thanks Claudio, but I'm afraid I have another problem. I tried to compile
the code that you send but it happened the same error: "parse error before
'.' token" at line: first.byte1=0x01;

------------------------------
//struct_test.c
typedef struct struct_test {
unsigned char byte1;
unsigned char byte2;
unsigned char byte3;
}struct_test;
struct_test first, second;

first.byte1=0x01;
------------------------------

My real application is trying to implement an UDP client that sends a
message to an UDP server. My code is the following and I had the same error
compiling it: "parse error before '.' token" at frst variable
initialization.

-------------------------------------
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
struct sockaddr_in cli, serv;

serv.sin_family=AF_INET;
serv.sin_addr.s_addr=inet_addr("192.168.200.6");
serv.sin_port=htons(6000);

cli.sin_family=AF_INET;
cli.sin_addr.s_addr=htonl(192.168.200.241);
cli.sin_port=htons(0);
---------------------------------------

Please someone have any idea ?

Thanks,
Fernanda.

----- Original Message -----
From: "Claudio Bley" <bley@cs.uni-magdeburg.de>
To: <gcc-help@gcc.gnu.org>
Sent: Monday, July 07, 2003 7:02 PM
Subject: 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]