Bit-wise operations as initial value of global (normal and extern variables)

 

Hi, 

I try to define a global variable with initial value like this:

#define A = 0x1;
#define B = 0x2; 
extern int X = A|B;

 I get a compilation error that says that , or ; are expected instead of the |. 

 When trying to to the same in a function, everything works great: 

int foo()
{

   int X = A|B;
   return(X);
}

Am I doing something wrong?

 

Thanks. 

 
Hi, yes:
#define A  0x1
#define B  0x2
and
int X = A|B;

Is it A/B?

 

 Is it A/B?

No, I am trying to perform a bitwise operation while defining the default value of a global variable. 

 
fudge:

No, I am trying to perform a bitwise operation while defining the default value of a global variable. 

It's not a Global variable,  it's a globally declared variable or a variable with global scope . . .  this is a Global Variable . . .  please use the correct terminology to be clear.

 

Why are you declaring it as an extern ?  and how do you expect to assign an expression to an extern ?  can you ?  

 
The right side of static, global (and externs) must be a constant.
#define A  0x1
#define B  0x2
#define AorB 0x3

extern int X = AorB;
 

RaptorUK, in terms of programming this is a global variable, since it's accessible by all functions in the program.
The global variable in MT4 is actually a shared memory that can be accessed by different custom indicators or ea's.

 

WHRoeder, thanks for clearing it up. I guess that MQL4 lacks some useful features :/.

 
fudge:

RaptorUK, in terms of programming this is a global variable, since it's accessible by all functions in the program.
The global variable in MT4 is actually a shared memory that can be accessed by different custom indicators or ea's.

You just used the same term "global variable"  for 2 completely different things . . .  now do you see why I asked you to be clear in the terminology you use . . .  
 
It makes me wonder why MQ didn't refer to GlobalVariableSet() [variables] by a different name.
 
ubzen:
It makes me wonder why MQ didn't refer to GlobalVariableSet() [variables] by a different name.
Yep,  it would have helped.  Maybe it got lost in translation ;-)
 
Maybe. I would have used local, static, common, and global
Reason: