Difference between revisions of "MaxInt"

From Lazarus wiki
Jump to navigationJump to search
m (Alextpp moved page maxint to MaxInt: proper casing of name)
(wikify)
 
Line 3: Line 3:
 
<br />
 
<br />
  
'''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].
+
'''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].
  
 
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.  
 
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.  
Line 9: Line 9:
 
If you want to check the size of the address space, check '''[[SizeOf|sizeof]]([[Pointer|pointer]])'''.
 
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.
+
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:

Latest revision as of 13:23, 22 December 2023

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