structure syntax error

This is a discussion on structure syntax error within the C Programming forums, part of the General Programming Boards category; this is the relevant section of a piece of code I am having trouble with. Code: struct waypointDef; struct waypointDef ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    5

    structure syntax error

    this is the relevant section of a piece of code I am having trouble with.
    Code:
    struct waypointDef;
    struct waypointDef waypoints[];
    waypointDef.waypoints[] = { {   (-800000000 - longin1) ,   (370000000 + latin1), 75 } , F_ABSOLUTE };
    The compiler returns with a syntax error before the '.' in waypointDef.waypoints[]. I have tried the same code without that line and it compiles fine. Can someone find my error?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    Code:
    struct waypointDef;
    struct waypointDef waypoints[] = { {   (-800000000 - longin1) ,   (370000000 + latin1), 75 } , F_ABSOLUTE };
    You must initialize on the declaration. Otherwise you can only assign.
    struct waypointDef; <--- Is this a forward declaration?
    struct waypointDef waypoints[]; <--- Must specify size.
    waypointDef.waypoints[] <--- Does waypointDef have a member waypoints, and is that what you're trying to initialize?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    i've also tried
    Code:
    struct waypointDef waypoints[] = { {   (-800000000) ,   (370000000), 75 } , F_ABSOLUTE };
    waypointDef.waypoints[] = { {   (-800000000 - longin1) ,   (370000000 + latin1), 75 } , F_ABSOLUTE };
    but got the same error.
    and yes, i am trying to initialize the member waypoints and then change its value
    do I have to specify size though? this same code works fine if I just remove the waypointDef.waypoints line
    thanks

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,245
    You cannot reassign in the way you're attempting in your second line.

    In your first line, the compiler is able to infer the size from the data you are using to initialise the array. That can only be done upon initialisation, not upon assignment after initialisation (which are the cases where your compiler is complaining).
    Right 98% of the time, and don't care about the other 3%.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    139
    Can i see the structure members?

  6. #6
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    This is the file -
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    How do you change values in a structure after initialization?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    By assigning to them individually
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    so do i have to abandon the structures entirely?
    or is there a less painful way to fix my code?

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    Either initialize the entire structure in one fell swoop, or assign them separately. Those are your two options.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    Yeah, you are not abandoning the use of structures. You are just assigning to the individual members of a structure. If you find it more convenience, write a function to help you do it.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. Includes making me insane >.<
    By IceDane in forum C Programming
    Replies: 14
    Last Post: 04-14-2008, 10:24 AM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM

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