Thread: typedef struct

  1. #1
    Registered User
    Join Date
    Jun 2006

    typedef struct

    I really shouldn't be posting this because i've done this before, but the way of doing it that i was 100% sure about is causing errors and I can't find example code that goes through the 10 or so lines that I need. My old source files were obliterated courtesy of Dev-C++, so I'll just go ahead and embarrass myself with 10 lines I just can't figure out.

    typedef struct
    	int lols;
    	int lol2;
    	int lol3;
    somestruct test;
    test.lol3 = 0;
    It's as if I didn't define 'test'. I can change 'test' in the assignment to anything and it still reports the same error.

    "syntax error before '.' token "

    In all honesty I can't believe I'm making this topic, but I just don't know what the hell is going on. Sorry for the stupid question.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    If you want to assign a value to a global struct, you either have to do it with an initializer, like this:
    somestruct test = { 1, 2, 3 };
    or inside a function, e.g. in main or some other function, in which case your syntax is correct - just not in the right place.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Thanks alot matsp. I'm not sure how I forget this stuff...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  3. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  4. typedef struct
    By ... in forum C++ Programming
    Replies: 5
    Last Post: 01-19-2004, 03:17 PM
  5. typedef struct question
    By flevine100 in forum C Programming
    Replies: 1
    Last Post: 09-03-2002, 09:34 PM