Const

Previous topic - Next topic

AndyH

I see const (lowercase) is recognised in the editor color coding.  I assume for inline C?  Any chance of having a GLB version too?

For example

INLINE
const int xorigin = 320;
const int yorigin = 240;
ENDINLINE

But I'd like (or somegthing similar)

CONST xorigin = 320
CONST yorigin = 240

So I can define my global constants somewhere (or even local ones in functions) rather than waste memory on variables.

Kitty Hello

I've got it on my WIP list.

AndyH

cool.  Thanks Gernot.

AndyH

BTW, I thought about using some constants for the key codes, coming from the Blitz world these constants are quite familiar and readable in the code.  If I put these in the main file:

Code (glbasic) Select
INLINE
const int KEY_ESCAPE=1;
const int KEY_1=2;
const int KEY_2=3;
const int KEY_3=4;
const int KEY_4=5;
const int KEY_5=6;
const int KEY_6=7;
const int KEY_7=8;
const int KEY_8=9;
const int KEY_9=10;
const int KEY_0=11;

ENDINLINE
I can refer to them in that same file.  If I try to refer to them in any other file in my project they do not exist.  Likewise if I define them in another file in my project I can not access them.  Is there anyway to make these constants global to the entire program?

Kitty Hello

There's already a solution for that with a TYPE.  Ah here it is:
http://www.glbasic.com/forum/viewtopic.php?id=679

AndyH

That's a great solution Gernot.  Thanks!  You should add a category to the built in help to contain useful code snippets such as this :)