A
atv
Alright, i have some questions concerning include files en global
variables.I hope someone is willing to answer these.
1).Why is it that if i define a global variable in a file, say main.c,
and i have also other functions defined in that file, i can use the
global in all functions, but once i split up the rest of the function in
other files, i cannot use the global? Isn't that strange, all the files
compiled should be treated as one program right ?
Or should i always define the variables somewhere, say main.c, and use
extern char var[]; in the other source files?
2). What is the proper way to use include files? If i split my code and
functions up in different files, what is the normal way of using
includes. Do you, each time for a new file, have a list of the includes
setup again in that file, or ?
Right now, i have a method i saw from some other code, by defining all
the include headers in one include.h, and using that include for all
files. That way you only have to include a file once, saves a lot of
typing. Is this a correct way or a very bad way of doing things.
3). I have code that is split up in multiple files. The main function
sits in main.c, and calls for example, a logging function, which sits
in log.c. Now log() needs to remember the amount of lines it has
written. How would i do this ? Declare a global in main and then use
extern int lines;? But that doesn't seem to work. What am i doing wrong?
Should it be static?
variables.I hope someone is willing to answer these.
1).Why is it that if i define a global variable in a file, say main.c,
and i have also other functions defined in that file, i can use the
global in all functions, but once i split up the rest of the function in
other files, i cannot use the global? Isn't that strange, all the files
compiled should be treated as one program right ?
Or should i always define the variables somewhere, say main.c, and use
extern char var[]; in the other source files?
2). What is the proper way to use include files? If i split my code and
functions up in different files, what is the normal way of using
includes. Do you, each time for a new file, have a list of the includes
setup again in that file, or ?
Right now, i have a method i saw from some other code, by defining all
the include headers in one include.h, and using that include for all
files. That way you only have to include a file once, saves a lot of
typing. Is this a correct way or a very bad way of doing things.
3). I have code that is split up in multiple files. The main function
sits in main.c, and calls for example, a logging function, which sits
in log.c. Now log() needs to remember the amount of lines it has
written. How would i do this ? Declare a global in main and then use
extern int lines;? But that doesn't seem to work. What am i doing wrong?
Should it be static?