Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with C syntax
#1
http://www.google.com/search?hl=en&ie=UT...%23declare

I can't figure out how to use #declare the same way you use CONST. I found this page:

http://www.povray.org/documentation/view/146/

But I'm not sure if it's even C!

Please help.
earn.
Reply
#2
Use #define.

Code:
#define YOURCONST 1234
printf("%d", YOURCONST);
Reply
#3
Plasma's solution will work but as an alternative you can use the const keyword:

Code:
const int x = 5;

printf("Constant x = %d\n", x);

The #define method given by Plasma has the preprocessor replace all occurances of YOURCONST with the string of text (its not actually a value as such) 1234 before compiling. This is fine for most solutions, except when you want some finer control, for example:

Code:
#define YOURCONST 1234
const int x = 5;

/* Okay, because x is a variable */
printf("Address of x = %d\n", &x);

/* Not okay, because YOURCONST is just a number */
printf("Address of YOURCONST = %d\n", &YOURCONST);
esus saves.... Passes to Moses, shoots, he scores!
Reply
#4
Thanks guys.
earn.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)