Thread: Calling structs in functinos

  1. #1
    Registered User
    Join Date
    Feb 2003

    Calling structs in functinos

    I'm working on a program right now that requires me to create a few structures and functions, and the functions must call the structures I've created. When I compile my program, I get various scope errors. My structs are defined in my main() routine. Do I have to move the structs outside of the main() routine to stop getting these scope errors, or can I just use:

    typedef struct name
    in my main() routine?

    Thanks for reading.

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Move the structure definition outside of main and you shouldn't have any problems :-)
    typedef struct {
      int i;
    } test;
    void f(test t)
      test d = t;
    int main()
      test t;

  3. #3
    Registered User
    Join Date
    Feb 2003
    Thanks for the help. I thought without the typedef I had to put struct in the function call. Thanks for clearing this up for me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack issues when calling a COM library
    By notnot in forum C Programming
    Replies: 3
    Last Post: 06-01-2009, 02:12 AM
  2. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  3. Multidimentional structs + memcpy() == FAIL
    By Viper187 in forum C Programming
    Replies: 8
    Last Post: 06-18-2008, 02:46 AM
  4. ArrayLists + Inner Structs
    By ginoitalo in forum C# Programming
    Replies: 5
    Last Post: 05-09-2002, 05:09 AM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM