LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   use typedef from another file - C (https://www.linuxquestions.org/questions/programming-9/use-typedef-from-another-file-c-881494/)

Fritz_Doll 05-18-2011 05:21 PM

use typedef from another file - C
 
I want to use a typedef defined in another file, but not sure how to do this; would also like to do the same thing for enums. How do I go about doing this?
main.c
Code:

void main(){
...
//Create DATA type variables here
DATA d1;
DATA d2;
...
}

second.c
Code:

struct dat{
int var1;
int var2;
};
typedef struct data DATA;


paulsm4 05-18-2011 05:54 PM

Assuming you're using C/C++, it sounds like a job for a header file, e.g.
Code:

#include "my_defs.h"

Fritz_Doll 05-18-2011 06:16 PM

Thanks, helped point me in the right direction. Very useful thing to know.


All times are GMT -5. The time now is 03:11 AM.