C Compiles backwards

Now a little post about C that apparently compiles backwards.

If you include some files into your project, the file that is included last can’t make use of the file you included first.

Example of how I experienced this habit of C:

main.c
#include “prep.h”
#include “run.h”

… some simple code here, cause I’ve written it myself …

prep.h
#include <nds.h>
#include “draw.h”
#include “button.h”

button.h
… do some things with u8 and u 16 …

This will result in the following error:
“error: expected declaration specifiers or ‘…’ before ‘u8′”

Because button.h needs nds.h, but it only is included in prep.h, apparently after button.h is compiled.
So you can remove the include of nds.h from prep.h and put it in a file that is the tiniest brick of your project! In my case I can inlude it in button.h and remove it from prep.h and main.c. Button.h with nds.h is compiled first, so prep and main can make use of the stuff of nds.h.

Prettig weekend !

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: