global Vars 
Author Message
 global Vars

How Can i use Global vars in a TC project.... ?

I have 3 ".C" files, and 3 header files...

If I put My Global vars In a Header File (included in the other two
sources files) I get an "declaration of var1 duplicated in module1 and
module2.

if I put my global vars in one of my source file, the other two file
(.c) doesn't recognize the existence of those global vars...

I don't get it... there's a way I'm sure...

Could someone help me please??

Thanks.

Alex

Montral, Canada



Sun, 04 Jan 1998 03:00:00 GMT  
 global Vars


Quote:
>How Can i use Global vars in a TC project.... ?

>I have 3 ".C" files, and 3 header files...

>If I put My Global vars In a Header File (included in the other two
>sources files) I get an "declaration of var1 duplicated in module1 and
>module2.

>if I put my global vars in one of my source file, the other two file
>(.c) doesn't recognize the existence of those global vars...

>I don't get it... there's a way I'm sure...

>Could someone help me please??

>Thanks.

>Alex

>Montral, Canada

----------------------------------
Read the manual next time!
But here goes.
declare your global vars in the  module file itself not in the header.
eg.
int i ; /* module 1 */
now declare i in module 2 as follows
extern int i; /* module 2 */

now you will be able to acccess i in module 2.

Cheers
Johann


I love Indigo Girls, Rock Climbing,
       Mountain Biking, Michele Shocked,
       and Rory Block



Mon, 05 Jan 1998 03:00:00 GMT  
 global Vars

Quote:
>How Can i use Global vars in a TC project.... ?

>I have 3 ".C" files, and 3 header files...

>If I put My Global vars In a Header File (included in the other two
>sources files) I get an "declaration of var1 duplicated in module1 and
>module2.

>if I put my global vars in one of my source file, the other two file
>(.c) doesn't recognize the existence of those global vars...

>I don't get it... there's a way I'm sure...

>Could someone help me please??

>Thanks.

>Alex

>Montral, Canada

What you need to do is declare these globals in one place, and refer to them
in other .c files using an "extern" declaration.




Mon, 05 Jan 1998 03:00:00 GMT  
 global Vars
Thanks to all those who replyed via e/mail...

Your help was greatly appreciated...!

Alexandre Payette
Montral, Canada



Tue, 06 Jan 1998 03:00:00 GMT  
 global Vars

asks:

Quote:
>How Can i use Global vars in a TC project.... ?
>I have 3 ".C" files, and 3 header files...
>If I put My Global vars In a Header File (included in the other two
>sources files) I get an "declaration of var1 duplicated in module1 and
>module2.
>if I put my global vars in one of my source file, the other two file
>(.c) doesn't recognize the existence of those global vars...
>I don't get it... there's a way I'm sure...
>Could someone help me please??

Try --
File1.c
    int x;
File2.c
    extern int x;
File3.c
    extern int x;

You will probably get good advice about headers, #defines, etc.  If you
understand it, follow it.  In the mean time, do the above.  BTW, this is
the general approach no matter what C compiler you use (not
tcc-specific) and whether you use "projects," makefiles, or compile each
file individually and link from the command line.
--

* Chicago, IL (USA)    



Wed, 07 Jan 1998 03:00:00 GMT  
 global Vars

Quote:
>----------------------------------
>Read the manual next time!
>But here goes.
>declare your global vars in the  module file itself not in the header.
>eg.
>int i ; /* module 1 */
>now declare i in module 2 as follows
>extern int i; /* module 2 */
>now you will be able to acccess i in module 2.

If I had a manual, I woulnd't have asked :)

I Just can't afford One right now... I must Learn On My own...

But when you do that, you sometime need advice from other persons...
like you... So thanks alot for taking the time to answer me... it was
pretty kind of you...

But I solved my problem 3 dayz ago :)

Alexandre
______________________________________________
Corrupted REALITY.SYS, Reboot Universe (Y/N) ?



Thu, 08 Jan 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. global vars vs: local vars

2. const global vars

3. Global vars versus pointers

4. how to access local and global vars in a function

5. static global vars and functions

6. Global vars, how to define them elegantly?

7. Global vars, another newbie question

8. Global Vars in a DLL with callback

9. Too many global vars... HELP!

10. ** Utility which identifies global vars used by (many) routines???

11. global/static vars inside loops

12. global/static vars inside loops

 

 
Powered by phpBB® Forum Software