October 30, 2025, 09:19:45 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Calculated constants

Started by Bruce Peaslee, December 27, 2005, 11:23:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee


const WHITEÂÃ,  = 0xFFFFFF;
const BLACKÂÃ,  = 0x000000;
const REDÂÃ,  ÂÃ,  ÂÃ, = 0x0000FF;
const GREEN = 0x00FF00;
const BLUEÂÃ,  ÂÃ, = 0xFF0000;

const YELLOW = RED|GREEN; // this works

const GRAY = RGB(127,127,127); //this doesn't


Are calculated constants something for the future?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

RGB is a function whose return is a variable.

RGB = r | g << 8| b<<16

So you could do

const gray = 127 | 127 << 8 | 127 << 16;

Paul.
Ionic Wind Support Team

Bruce Peaslee

That works. Paranthesis make it easier to read:ÂÃ,  ÂÃ, ;>)

const gray = 127 | (127 <<ÂÃ,  8) | (127 << 16);

(One needs to turn smilies "off" to get this right.)
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Bruce Peaslee

I think I should know better. Aren't constants defined during compilation and RGB() returns a value at runtime?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

Yes, all functions' values are determined at runtime, while constants are resolved at compile time. If RGB was a macro, you'd be able to do what you were saying.