Go to Post "THAT'S NOT SAFE!" "But I'm wearing safety goggles!" - Samheartsrobots [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-02-2006, 13:13
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
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
I searched all the project files and nothing else uses _TRACKING_H, so why have it?
__________________
http://www.mikesorrenti.com/
  #2   Spotlight this post!  
Unread 08-02-2006, 13:21
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
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;
file2.h is the following:
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
If you did the above, then var1, var2, var3, and var4 would be defined twice, which is a bad thing. Using the #infdef/#define/#endif would keep this from happening.
__________________
-
An ounce of perception is worth a pound of obscure.
  #3   Spotlight this post!  
Unread 08-02-2006, 17:28
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
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()
}
Basically, the compiler comes through and evaluates the if statement. If it is true, then it will include what is between #if and #endif. Otherwise, it is as if that code is not even there. It's an improvement over using actual code to block out bits, because it doesn't take any of your memory on the robot, and doesn't take any run-time computation to determine whether or not to run printf("shooting!").

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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 01:33.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi