Jump to content
  • Advertisement


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


prototypes and headerfiles?

This topic is 5983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites
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?


Share this post

Link to post
Share on other sites
The filename is still "prototypes.h"(notice the full stop instead of the underscore) - so it should be #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

Share this post

Link to post
Share on other sites
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...*


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!