Difference between revisions of "MaxInt"

From Lazarus wiki
Jump to navigationJump to search
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{maxint}}
  
'''MAXINT''' is a global constant, equal to the upper bound of the [[Integer|integer]] type, [http://www.moorecad.com/standardpascal/iso7185.html#6.7.2.2%20Arithmetic%20operators per the ISO 7185 standard].
+
<br />
  
Note that this value changes based on the compiler mode and has nothing to do with the capabilities of the host or target machine.  
+
'''MAXINT''' is a global [[Constant|constant]], equal to the upper bound of the [[Integer|integer]] type, [http://www.moorecad.com/standardpascal/iso7185.html#6.7.2.2%20Arithmetic%20operators per the ISO 7185 standard].
  
If you want to check the size of the address space, check '''sizeof(pointer)'''.
+
Note that this value changes based on the [[Compiler Mode|compiler mode]] and has nothing to do with the capabilities of the host or target machine.  
  
If you want to know if you are running on a CPU with 64-bit ALU, check whether the symbol '''cpu64''' is defined.
+
If you want to check the size of the address space, check '''[[SizeOf|sizeof]]([[Pointer|pointer]])'''.
 +
 
 +
If you want to know if you are running on a CPU with [[64 bit|64-bit]] ALU, check whether the symbol '''cpu64''' is defined.
  
 
The following example illustrates how these values relate:
 
The following example illustrates how these values relate:
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
program maxvals;
 
program maxvals;
 
   const width = 20;
 
   const width = 20;
Line 38: Line 41:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Compare the results with '''-Mtp''' vs '''-Mobjfpc''', for example:
+
Compare the results with [[Mode_TP|'''-Mtp''']] vs [[Mode_ObjFPC|'''-Mobjfpc''']], for example:
  
 
<pre>
 
<pre>
Line 44: Line 47:
 
fpc -Mobjfpc maxvals.pas && ./maxvals
 
fpc -Mobjfpc maxvals.pas && ./maxvals
 
</pre>
 
</pre>
 
[[Category:Constants]]
 
[[Category:Processors]]
 

Revision as of 08:56, 30 June 2019

English (en)


MAXINT is a global constant, equal to the upper bound of the integer type, per the ISO 7185 standard.

Note that this value changes based on the compiler mode and has nothing to do with the capabilities of the host or target machine.

If you want to check the size of the address space, check sizeof(pointer).

If you want to know if you are running on a CPU with 64-bit ALU, check whether the symbol cpu64 is defined.

The following example illustrates how these values relate:

program maxvals;
  const width = 20;
begin
  writeln;
  writeln( 'these change depending on compiler mode:' );
  writeln( '----------------------------------------' );
  writeln( 'maxint:           :', maxint : width );
  writeln( 'high( integer )   :', high( integer ) : width );
  writeln;
  writeln( 'constant, regardless of mode or target: ' );
  writeln( '----------------------------------------' );
  writeln( 'high( int32 )     :', high( int32 ) : width );
  writeln( 'high( int64 )     :', high( int64 ) : width );
  writeln;
  writeln( 'variable, depending on target cpu:' );
  writeln( '----------------------------------------' );
  writeln( 'sizeof( pointer ) :', sizeof( pointer ) : width );
  writeln;
  writeln( 'compile-time definitions:' );
  writeln( '----------------------------------------' );
  {$IFDEF cpu64} writeln( 'cpu64' ); {$ENDIF}
  {$IFDEF cpu32} writeln( 'cpu32' ); {$ENDIF}
  {$IFDEF cpu16} writeln( 'cpu16' ); {$ENDIF}
  writeln;
end.

Compare the results with -Mtp vs -Mobjfpc, for example:

fpc -Mtp maxvals.pas && ./maxvals
fpc -Mobjfpc maxvals.pas && ./maxvals