Thread: How to pass a typedef struct to function?

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    16

    How to pass a typedef struct to function?

    Hi, I'm trying to understand how to pass typedef structures to a function. The following is how I'm trying to do it, but it doesn't work (parse errors). What am I doing wrong?

    Code:
    #include <stdio.h>
    
    void func(test, test); // parameter name warning occurs here
    
    int main()
    {
       typedef struct{
          int a, b, c;
       } test;
       test here, there;
    
       //.........
    
       func(here, there);
    
       return 0;
    }
    
    void func(test here, test there) // parse error occurs here
    {
       //........
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    declare your structure outside of the function.
    Code:
    #include <stdio.h>
    
    typedef struct{
          int a, b, c;
       } test;
    
    void func(test, test); // parameter name warning occurs here
    
    int main()
    {
       
       test here, there;
    
       //.........
    
       func(here, there);
    
       return 0;
    }
    
    void func(test here, test there) // parse error occurs here
    {
       //........
    }

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    16
    That fixed it, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM