Syntax error before '.' token...

This is a discussion on Syntax error before '.' token... within the C Programming forums, part of the General Programming Boards category; the following code is giving me the error: syntax error before '.' token Code: struct point zero; zero.location[0]=0; zero.location[1]=0;zero.location[2]=0; zero.coords[0]=0;zero.coords[1]=0;zero.coords[2]=0; ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    11

    Syntax error before '.' token...

    the following code is giving me the error:
    syntax error before '.' token

    Code:
    struct point zero;
    	zero.location[0]=0;	
    	zero.location[1]=0;zero.location[2]=0;
    	zero.coords[0]=0;zero.coords[1]=0;zero.coords[2]=0;
    	zero.p_xyz[0]=NULL;zero.p_xyz[1]=NULL;zero.p_xyz[2]=NULL;
    	zero.p_xyz_n[0]=NULL;zero.p_xyz_n[1]=NULL;zero.p_xyz_n[2]=NULL;
    why is it so??

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    Wow, here's a shortcut way to initialize your struct:
    Code:
    struct point zero = { 0 };
    Much cleaner, yeah?

    Also, compilers may not care about the amount/lack of whitespace, but humans usually do.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    11
    are the pointers also initialized to NULL?

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    NULL is usually just defined as ((void *) 0) or just 0. So in short, yes they are. Use of zero or NULL to initialize pointers is stylistic, the compiler does the same initialization either way.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    According to the ISO C99 standard:

    Section 6.7.8, constraint #19:
    The initialization shall occur in initializer list order, each initializer provided for a
    particular subobject overriding any previously listed initializer for the same subobject;
    all subobjects that are not initialized explicitly shall be initialized implicitly the same as
    objects that have static storage duration.
    Section 6.7.8, constraint: #10:
    If an object that has automatic storage duration is not initialized explicitly, its value is
    indeterminate. If an object that has static storage duration is not initialized explicitly,
    then:
    if it has pointer type, it is initialized to a null pointer;

    if it has arithmetic type, it is initialized to (positive or unsigned) zero;
    if it is an aggregate, every member is initialized (recursively) according to these rules;
    if it is a union, the first named member is initialized (recursively) according to these
    rules.
    In short, yes.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    11
    thanks for the help guys..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21