Excellent Article Regarding Header/Source Files

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
dandymcgee
ES Beta Backer
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

Post by dandymcgee »

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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Excellent Article Regarding Header/Source Files

Post by avansc »

the only important thing in that whole article was this

"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"
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Re: Excellent Article Regarding Header/Source Files

Post by JS Lemming »

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!
User avatar
dandymcgee
ES Beta Backer
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

Post by dandymcgee »

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! :twisted:
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: Excellent Article Regarding Header/Source Files

Post by Arce »

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'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?
xD, congrats, you've managed to turn this discussion into some kind of a deep philosophical question. xD

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
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Excellent Article Regarding Header/Source Files

Post by avansc »

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?
its really not that hard.

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"
Post Reply