Log in

View Full Version : #define creation


NASAbound1636
02-02-2006, 16:30
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
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#define MY_CONSTANT 1

my_file.c#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
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:

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
you can do stuff like #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