LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

related to C string and file handling

Hi ,
 
In an application programme I am using two C files(say  F1.c and F2.c ). In F1.c I have declared a structure named
 
struct A
{
 
int i;
 
}Object;
 
Now when I am using this structure in other file F2.c the structure object and struct variable , compiler says undefined variable etc .
now tell me how to declare the variables ( i.e Object & i) in F2.c and use these in F2.c ?
 
subrata
0 Kudos
Message 1 of 5
(3,801 Views)
You need to use a header file, containing the structure definition and #included by both of your c files. I would use a system similar to this:
 
<this is a new header file, eg defs.h>

typedef struct A {        // I prefer to use typedefs, especially in a header file
    int i;
} structA;

extern structA Object;    // This tells the compiler that another source
                          //  file is responsible for defining the variable

<within your F1.c and F2.c files, include this line:>

#include "defs.h"

<within just one of your source files (it does not really matter which), you need to define the actual variable at the top level>

structA Object;

In this manner, both your c files are aware of the single Object at compile time.
 
JR

Message Edited by jr_2005 on 03-08-2007 10:41 AM

Message 2 of 5
(3,795 Views)
I see object name does not generate any error during compilation but the structure variable i.e int  i  ; causes the error .
 
subrata
0 Kudos
Message 3 of 5
(3,791 Views)

Could you post a copy of the line which the compiler complains about?

JR

0 Kudos
Message 4 of 5
(3,787 Views)

Hello JR ,

 

Your suggestion is working now .Thanks a lot

subrata

0 Kudos
Message 5 of 5
(3,760 Views)