prototypes and headerfiles?
Hello! I have moved all my prototypes into a header file, and that header is included in all my code files. But when i try to compile the compiler gives me the error that all my prototypes are already defined. I guess this is because they are inculded in several files. How can i solve this?
Thanks!
//olle
Use something like this:
Those who do not love don''t live.
#ifndef _SOME_H_#define _SOME_H_// Your prototypes#endif
Those who do not love don''t live.
Hey!
What LordLethis means is that you can use whatever you want, but it''s easier to use descriptive names. For example, if you want to include myhead.h, put
#ifndef MYHEAD_H
#define MYHEAD_H
// put your code here
#endif MYHEAD_H
at the beginning and end of myhead.h.
What this does is that the header file is only included once per compile.
What LordLethis means is that you can use whatever you want, but it''s easier to use descriptive names. For example, if you want to include myhead.h, put
#ifndef MYHEAD_H
#define MYHEAD_H
// put your code here
#endif MYHEAD_H
at the beginning and end of myhead.h.
What this does is that the header file is only included once per compile.
"It's strange, isn't it? You stand in the middle of a library and go 'AAAAAAAGGHHHH' and everyone just stares at you. But you do the same thing on an airplane, and everyone joins in!"
Exactly.
You can use anything except reserved keywords instead of _SOME_H_.
And if this does not solve the problem and if your using MSVC, set the option /force:multiple in the linker options.
Those who do not love don''t live.
[MSDN|Google|Bloodshed|My lousy page|email.me]
You can use anything except reserved keywords instead of _SOME_H_.
And if this does not solve the problem and if your using MSVC, set the option /force:multiple in the linker options.
Those who do not love don''t live.
[MSDN|Google|Bloodshed|My lousy page|email.me]
Hello. Im afraid i still dont get it. :|
I have three prototypes. Every one of those functions are in its own file, and prototypes.h is my header file containing them. Prototypes.h looks like this now:
#ifndef prototypes_h
#define prototypes_h
int Game_Init();
int Game_Shutdown();
int Game_Main();
#endif prototypes_h
So now i should use: ''#include "prototypes_h" '' in all my code files right? But that gives me this error:
fatal error C1083: Cannot open include file: ''prototypes_h'': No such file or directory
What am i doing wrong?
Thanks!
I have three prototypes. Every one of those functions are in its own file, and prototypes.h is my header file containing them. Prototypes.h looks like this now:
#ifndef prototypes_h
#define prototypes_h
int Game_Init();
int Game_Shutdown();
int Game_Main();
#endif prototypes_h
So now i should use: ''#include "prototypes_h" '' in all my code files right? But that gives me this error:
fatal error C1083: Cannot open include file: ''prototypes_h'': No such file or directory
What am i doing wrong?
Thanks!
The filename is still "prototypes.h"(notice the full stop instead of the underscore) - so it should be
"The churches used to win their arguments against atheism, agnosticism, and other burning issues by burning the ismists, which is fine proof that there is a devil but hardly evidence that there is a God."
Ben Lindsey and Wainwright Evans
#include "prototypes.h"
"The churches used to win their arguments against atheism, agnosticism, and other burning issues by burning the ismists, which is fine proof that there is a devil but hardly evidence that there is a God."
Ben Lindsey and Wainwright Evans
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
No, keep including "prototypes.h", since that''s the actual file you''re using.
What you were being told to do was add some preprocessor commands. These commands go to the compiler and help it decide what code to use when.
In this case, the prototype_h is just the name of a flag. When you say #ifndef prototype_h, you are asking the compiler to use all of the code up to the #endif if and only if prototype_h hasn''t been defined before. The next command (#define prototype_h) defines it. By doing this, it ensures that if it ever gets to the #ifndef line again, it will already be defined and hence skip the code in the header. So no matter how many files include "prototype.h", the prototypes in it will only be declared once.
For more information, look up preprocessor macros in your help files or on the internet.
*hoping that made sense...*
-Auron
What you were being told to do was add some preprocessor commands. These commands go to the compiler and help it decide what code to use when.
In this case, the prototype_h is just the name of a flag. When you say #ifndef prototype_h, you are asking the compiler to use all of the code up to the #endif if and only if prototype_h hasn''t been defined before. The next command (#define prototype_h) defines it. By doing this, it ensures that if it ever gets to the #ifndef line again, it will already be defined and hence skip the code in the header. So no matter how many files include "prototype.h", the prototypes in it will only be declared once.
For more information, look up preprocessor macros in your help files or on the internet.
*hoping that made sense...*
-Auron
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement