If you're at all confused about the pros and cons of splitting your project into multiple source files, or if you have already decided to do so and are having some problems I would Highly recommend giving this article a read:
http://www.gamedev.net/reference/progra ... /orgfiles/
I'm so happy this exists, haha. It has helped me So much. Hopefully it will help someone else too.
Excellent Article Regarding Header/Source Files
Moderator: Coders of Rage
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Excellent Article Regarding Header/Source Files
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: Excellent Article Regarding Header/Source Files
the only important thing in that whole article was this
"Add an inclusion guard to every header file you make "
i never knew people had such a hard time with something as elementary as header files.
"Add an inclusion guard to every header file you make "
Code: Select all
#ifndef _INC_STDLIB
#define _INC_STDLIB
...
#endif _INC_STDLIB
i never knew people had such a hard time with something as elementary as header files.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
Re: Excellent Article Regarding Header/Source Files
I've always had a hard time splitting things into header files. It seems abstract to me. How one thing could warrant having it's own file and another not. Who am I to decide such things. How could I?
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Excellent Article Regarding Header/Source Files
Same here, I'm still trying to fully grasp the concept of exactly what sorts of things to put in which files. It's definitely simpler since I read that.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: Excellent Article Regarding Header/Source Files
Yeah, actually...The majority of my programming class looked at me like I was some kind of god because of the use of a few headers and source files...o.o;
Honestly, I never knew it was such a big deal either--there's no way in fuck I'd ever wade through all my source in a single file to find a function. Especially with larger programs...I'd simply kill myself.
The only thing I think would be difficult for others inexperienced with neat code (headers and source files) would have a hard time with is cutting out problems with multiple declarations, and prototyping correctly...Both easy fixes.
I personally say follow your own rules, unless you're abiding by some kind of company standard...Just stay consistent, and you'll be good...
Honestly, I never knew it was such a big deal either--there's no way in fuck I'd ever wade through all my source in a single file to find a function. Especially with larger programs...I'd simply kill myself.
The only thing I think would be difficult for others inexperienced with neat code (headers and source files) would have a hard time with is cutting out problems with multiple declarations, and prototyping correctly...Both easy fixes.
xD, congrats, you've managed to turn this discussion into some kind of a deep philosophical question. xDI've always had a hard time splitting things into header files. It seems abstract to me. How one thing could warrant having it's own file and another not. Who am I to decide such things. How could I?
I personally say follow your own rules, unless you're abiding by some kind of company standard...Just stay consistent, and you'll be good...
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
Re: Excellent Article Regarding Header/Source Files
its really not that hard.JS Lemming wrote:I've always had a hard time splitting things into header files. It seems abstract to me. How one thing could warrant having it's own file and another not. Who am I to decide such things. How could I?
if you are making a class, that automatically goes in its own class_name.h and class_name.c/cpp file
the declaration and prototypes go in the .h file and the definition goes in the source file.
if you are data type that gets its own header and source file.
headers always just have prototypes/declaration, and there is a corresponding .c/cpp files with the definitions/code of those member functions and jazz.
a main source file should always be very small. for a game maybe 100 lines.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"