Qbasicnews.com
May 23, 2022, 09:59:20 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Help with C syntax  (Read 2121 times)
seph
Na_th_an
*****
Posts: 1915



« on: June 11, 2003, 11:55:18 PM »

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=c+documentation+%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.
Logged

earn.
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #1 on: June 12, 2003, 01:43:24 AM »

Use #define.

Code:
#define YOURCONST 1234
printf("%d", YOURCONST);
Logged
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #2 on: June 12, 2003, 02:39:29 AM »

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);
Logged

esus saves.... Passes to Moses, shoots, he scores!
seph
Na_th_an
*****
Posts: 1915



« Reply #3 on: June 12, 2003, 09:14:44 AM »

Thanks guys.
Logged

earn.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!