Difference between revisions of "false and true"

From Lazarus wiki
Jump to navigationJump to search
(use Template:Translate; add hint about typecasting)
Line 5: Line 5:
  
 
These constant values must be predefined by the compiler as there is no way to define them in terms of anything else.
 
These constant values must be predefined by the compiler as there is no way to define them in terms of anything else.
 +
They are [[Reserved words|reserved words]] for [[FPC]].
  
 
== internal value ==
 
== internal value ==
Line 32: Line 33:
  
 
When [[Typecast|typecasting]] or interpreting any numeric value as a boolean value, it is important to know, that ''any'' non-zero value means <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight> whilst only <syntaxhighlight lang="pascal" enclose="none">0</syntaxhighlight> (zero) is <syntaxhighlight lang="pascal" enclose="none">false</syntaxhighlight>.
 
When [[Typecast|typecasting]] or interpreting any numeric value as a boolean value, it is important to know, that ''any'' non-zero value means <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight> whilst only <syntaxhighlight lang="pascal" enclose="none">0</syntaxhighlight> (zero) is <syntaxhighlight lang="pascal" enclose="none">false</syntaxhighlight>.
 +
 +
[[Category:Code]]
 +
[[Category:Pascal]]
 +
[[Category:Reserved words]]

Revision as of 13:03, 4 May 2018

Template:Translate

The constants false and true are used to define the false and true conditions of a boolean variable. They are manifest constants that are defined as part of the standard data types the compiler initially knows about.

These constant values must be predefined by the compiler as there is no way to define them in terms of anything else. They are reserved words for FPC.

internal value

program falseDemo(input, output, stderr);

uses
	typInfo;

begin
	writeLn(false);                            // prints FALSE
	
	// enumerative actions ------------------------------------------
	writeLn(ord(false));                       // prints 0
	writeLn(succ(false));                      // prints TRUE
	// next two statements generate out-of-range compile-time warnings
	writeLn(pred(false));                      // prints TRUE
	writeLn(succ(succ(false)));                // prints TRUE
	
	// data type ----------------------------------------------------
	writeLn(sizeOf(false));                    // prints 1
	writeLn(bitSizeOf(false));                 // prints 8
	writeLn(PTypeInfo(typeInfo(false))^.kind); // prints tkBool
	writeLn(PTypeInfo(typeInfo(false))^.name); // prints Boolean
end.

When typecasting or interpreting any numeric value as a boolean value, it is important to know, that any non-zero value means true whilst only 0 (zero) is false.