Thread: structure syntax error

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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,815
    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%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

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

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

  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
    28,413
    By assigning to them individually
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 05:45 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM