Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   #define creation (http://www.chiefdelphi.com/forums/showthread.php?t=43169)

NASAbound1636 02-02-2006 16:30

#define creation
 
I am trying to complicate my autonomous file by creating a new variable set to run off of and i need to know how to create a #define code in my .h files so it doesn't spit massive error messages at me for using a "not defined" variable, any instructions on how to properly define something would be nice.

Dave Scheck 02-02-2006 16:55

Re: #define creation
 
I'm a little confused by your question, but this is how you correctly define a constant in a header and then use it in a C file

my_header.h
Code:

#define MY_CONSTANT 1
my_file.c
Code:

#include "my_header.h"
int x  = MY_CONSTANT;

There's not really much more to it than that.

Alan Anderson 02-02-2006 21:12

Re: #define creation
 
It sounds like you want to "declare a variable", not "define" anything. Using #define is typically for constants and shortcuts to save typing. What you're probably looking for is something like this:
Code:

  int auto_timer;
  char last_contact;

If you give more information about how you want to use the variable, we can provide more detailed directions on how and where to declare it.

Gamer930 02-02-2006 23:40

Re: #define creation
 
you can do stuff like
Code:

#define GLOBE_MOTOR pwm03
Couple Tips:
- Normally all constants have capital letters
- Use names to label pwm's like in the example above. I found that is it much easier for a Dummy programmer to understand that the code is right and that it is something mechanical :D


All times are GMT -5. The time now is 16:30.

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