|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Defining file name?
I've noticed this in a couple IFI files, and figured it was just some necessary thing for the IFI code, but now it's in Kevin's code and I'm curious.
Why, at the start of most .h files, do we have something similar to Code:
#ifndef _TRACKING_H #define _TRACKING_H |
|
#2
|
||||||
|
||||||
|
Re: Defining file name?
This is so that the code is included only once. For example, let's say you have three files: file1.h, file2.h, and file3.c.
file1.h is the following: Code:
// file1.h int var1, var2; char var3, var4; Code:
// file2.h #include "file1.h" int var5; finally, file3.c is the following: Code:
// file3.c #include "file1.h" #include "file2.h" // code here |
|
#3
|
||||
|
||||
|
Re: Defining file name?
Since the question was already answered, here's more info.
You can do other fun things with preprocessor stuff like that. Example: What if you wanted your code to do something while you were debugging, and something else in your 'production' or complete competition code? Code:
#define DEBUG
int shoot()
{
#ifdef DEBUG
printf("shooting!")
#endif
shootTheBall()
}
So when you're debugging, you just #define DEBUG. When you want your final code to be faster/smaller, just remove the #define DEBUG line, and all your debug-related things will be removed. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| .hex file too large for 2004 controller? | AL_E | Programming | 6 | 21-01-2006 22:54 |
| Reading binary data from a file and writing it in VB | complete | Programming | 1 | 02-01-2006 21:21 |
| C HELP PLEASE | sglegend11 | Programming | 4 | 14-11-2005 21:35 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |
| Dashv2.ocx dependency file now available | archiver | 2000 | 0 | 23-06-2002 22:00 |