Download MetaTrader 5

Whats the difference between true , TRUE and True ?

To add comments, please log in or register
Reza nasimi
258
Reza nasimi  
Carl Schreiber
7674
Carl Schreiber  

If the compiler doesn't complain - no difference.

Ex Ovo Omnia
3388
Ex Ovo Omnia  
Reza nasimi
258
Reza nasimi  
JC
1588
JC  
Ex Ovo Omnia:

Not really important, just the 'true' seems to be a 1-byte boolean constant, while TRUE and True are 4-byte integer constants of value 1.

(Massively pedantic answer...

Yes, it's MT4 inheriting from Windows, which in turn is reflecting the historic differences between C and C++. C has - strictly, had - no boolean data type and no "true" constant. Therefore, the Windows API fills the gap by defining a BOOL, which is simply "typedef int BOOL", and by defining the constant TRUE, which is simply "#define TRUE 1". C++ does have a bool data type, and does have a "true" constant. MQL4 inherits these two separate things. This has been tidied up in MQL5, which only has "true", and doesn't have "TRUE" or "True".)

Blahtech Limited
6410
James Cater  
JC:

(Massively pedantic answer...

Yes, it's MT4 inheriting from Windows, which in turn is reflecting the historic differences between C and C++. C has - strictly, had - no boolean data type and no "true" constant. Therefore, the Windows API fills the gap by defining a BOOL, which is simply "typedef int BOOL", and by defining the constant TRUE, which is simply "#define TRUE 1". C++ does have a bool data type, and does have a "true" constant. MQL4 inherits these two separate things. This has been tidied up in MQL5, which only has "true", and doesn't have "TRUE" or "True".)

MQL4 is loosely based on C++ which has always had a bool type.

ANSI C did not have a bool until 1999. The current ANSI standard is C11 (2011)

Many compilers did not implement all the C99 features and so C90 may still be the most portable version

https://stackoverflow.com/questions/1608318/is-bool-a-native-c-type

Is bool a native C type?
Is bool a native C type?
  • stackoverflow.com
I've noticed that the Linux kernel code uses bool, but I thought that bool was a C++ type. Is bool a standard C extension (e.g., ISO C90) or a GCC extension?
JC
1588
JC  
James Cater:

ANSI C did not have a bool until 1999. The current ANSI standard is C11 (2011)

Yes, that is indeed what I meant by "C has - strictly, had - no boolean data type". From Windows's point of view, C doesn't have a bool because the core of the Windows API predates 1999.

Blahtech Limited
6410
James Cater  
JC:

Yes, that is indeed what I meant by "C has - strictly, had - no boolean data type". From Windows's point of view, C doesn't have a bool because the core of the Windows API predates 1999.

Seems like Microsoft finally implemented the bool type in their C compiler with the release of  Visual Studio 2013...

https://msdn.microsoft.com/en-us/library/hh409293(v=vs.120).aspx

JC
1588
JC  
James Cater:

Seems like Microsoft finally implemented the bool type in their C compiler with the release of  Visual Studio 2013...

Windows API obviously continues to use its own definition of BOOL; too late to change that.

Digressing almost completely, my favourite Windows->MQL4 legacy is one I've mentioned a couple of times before on this forum...

Question: why isn't is possible for an indicator or a line object in MT4 to be dashed, dotted etc if it is more than 1 pixel wide? Answer: it's almost certainly inheriting the limitations of the Windows CreatePen() function. That dates back at least to 1995, and may well derive from Windows 3, or even beyond - I can no longer remember.

To add comments, please log in or register