gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Using header or other .c files

#132571 - calcprogrammer1 - Wed Jun 27, 2007 9:49 pm

Is there a way to make your own header (.h) or .c files other than main.c? Is there a way to take a bunch of functions, such as those needed for a side scrolling game, and move them to another file so that the main.c will be easier to edit other things in? I tried copying all my menu functions to a file, renaming it menus.h, then putting #include "menus.h" in my file, but it had errors with <something> isn't defined or something.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#132572 - Lick - Wed Jun 27, 2007 9:52 pm

Yes, "main.c" is just to indicate to other programmers that the main function is there. You can rename "main.c" to whatever you want, or put the main function anywhere else.
_________________
http://licklick.wordpress.com

#132575 - calcprogrammer1 - Wed Jun 27, 2007 10:00 pm

I think I got it working...I had two functions:

displaySplash() and displayMainMenu() that I wanted to get out of main.c.

I moved them to a file called menus.h then put

#include "menus.h"

void displaySplash();
void displayMainMenu();

and it said something about a data file, so I put the includes for my .gif images in the header as well as main and it compiled.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#132584 - tepples - Wed Jun 27, 2007 11:04 pm

In general, do not put code in a .h file. Instead, put it in another .c file, keep only the function's prototype in the .h file, compile this .c file to a .o file, and link this .o file into your .elf file. Are you using wintermute's makefile?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#132595 - calcprogrammer1 - Thu Jun 28, 2007 12:47 am

I'm using PAlib for Visual C++ 2005 Express...I've used VC++ for PC stuff already so I found the application package and am trying that. I tried to learn libnds originally but it was confusing for starting on. I'll change the .h into a .c, and once I get familiar with the DS some more I'll go to libnds possibly.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.