GLBasic forum

Main forum => Bug Reports => Topic started by: MrTAToad on 2010-Jan-29

Title: Inline variable access problem
Post by: MrTAToad on 2010-Jan-29
With the following :

Code (glbasic) Select
CONSTANT PTR_BCONTAINER% = -1
CONSTANT PTR_CONTAINER% = 0
CONSTANT PTR_WINDOW% = 1

INLINE
switch (ptrType) {
case PTR_BCONTAINER :
container->add(label,x,y);
break;

case PTR_WINDOW :
{
gcn::Window *win;

win=(gcn::Window *) ptr;
win->add(label,x,y);
}
break;

case PTR_CONTAINER:
{
gcn::Container *container;

container=(gcn::Container *) ptr;
container->add(label,x,y);
}
break;
};
ENDINLINE


I get the following error :

C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp1.cpp: In function `DGNat __GLBASIC__::GUI_CreateLabel(DGNat, DGNat, DGNat, __GLBASIC__::DGStr, DGNat)':
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp1.cpp:670: error: `__GLBASIC__::PTR_BCONTAINER' cannot appear in a constant-expression

It appears that putting -1 in brackets (-1) doesn't solve the problem :

Code (glbasic) Select
CONSTANT PTR_BCONTAINER% = (-1)
Title: Re: Inline variable access problem
Post by: MrTAToad on 2010-Feb-01
It is also fine is if "if" statements are used instead of switch...
Title: Re: Inline variable access problem
Post by: Kitty Hello on 2010-Feb-01
ah, no. The GLBasic CONSTANT does _not_ make a const int in C++. If you want that, you must define it explicitly in inline.
Title: Re: Inline variable access problem
Post by: MrTAToad on 2010-Feb-03
Ah, right - strange it was working with some variables though...