default settings of structs

Back to topics list To post a new topic, please log in or register
avatar
2017
gooly 2015.08.25 22:06
 

Hi,

does anybody know how the initial values of a struct are set?

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
struct __test {
   int i;
   bool isFalse;
};
void OnStart()
  {
//---
   __test x;
   Comment("False: ",x.isFalse,"  i: ",x.i);
   Print("False: ",x.isFalse,"  i: ",x.i);
   DebugBreak();
  }

The result I get:

2015.08.25 22:02:49.193 struct_test EURUSD,M5: False: true  i: 259979672

Normally any boolean variable is set to  0 (=false) and integers to 0 too.

On the other hand a boolean variable 'within' a struct will always be set true?

And what does i=259 979 672 mean? The highest integer is 2 147 483 647.

Gooly

avatar
1109
Ovo 2015.08.25 22:28 #
 
Structures are not initialized, only allocated. If you need implicit initialization, add the default constructor.
Back to topics list  

To add comments, please log in or register