Archived

This topic is now archived and is closed to further replies.

C code Organization

Recommended Posts

Jess    122
I have lot of troubles with organizate the code in C (I''m not talking about C++). I am making a OpenGl program that works in only .c file, or separate in a winmain .c file and 4 .h headers, my GLDraw function that it is only in one header file, but if in this GLDraw function I want to use a variable that is used too in winmain.c file I get only errors or no results in screen. I have tested extern and static, but it doesn''t works on me, or I don''t know to use it right. Anyone can help me or tell me some links about organization C code in modules? (remember not C++ like the article in this web)

Share on other sites
randomZ    163

Haven''t looked at them exactly, but they seem usable.

The basics in short:

- Don''t put any code in header files, only forward declarations and other declarations (structs, typedefs...). You would get duplicate definitions otherwise.

- If you want to use a variable from another file:

  // file1.cint a; // variable is declared here// file2.cextern int a; // This variable exists in some other file

"George W. Bush Geography Simplification Initiative"

My Homepage (C++ SDL OpenGL Game Programming)