MaxInt: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | 1 | **MaxInt** is a global [[Constant|constant]], equal to the upper bound of the [[Integer|integer]] type, [per the ISO 7185 standard](http://www.moorecad.com/standardpascal/iso7185.html#6.7.2.2%20Arithmetic%20operators). | |
| 3 | 2 | ||
| 4 | 3 | 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. | |
| 5 | 4 | ||
| 6 | 5 | If you want to check the size of the address space, check **[[SizeOf|sizeof]]([[Pointer|pointer]])**. | |
| 7 | 6 | ||
| 8 | 7 | 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. | |
| 9 | 8 | ||
| 10 | 9 | The following example illustrates how these values relate: | |
| 11 | 10 | ||
| 12 | 11 | ``` pascal | |
| 13 | 12 | program maxvals; | |
| 14 | 13 | const width = 20; | |
| 15 | 14 | begin | |
| 16 | 15 | writeln; | |
| 17 | 16 | writeln( 'these change depending on compiler mode:' ); | |
| 18 | 17 | writeln( '----------------------------------------' ); | |
| 19 | 18 | writeln( 'maxint: :', maxint : width ); | |
| 20 | 19 | writeln( 'high( integer ) :', high( integer ) : width ); | |
| 21 | 20 | writeln; | |
| 22 | 21 | writeln( 'constant, regardless of mode or target: ' ); | |
| 23 | 22 | writeln( '----------------------------------------' ); | |
| 24 | 23 | writeln( 'high( int32 ) :', high( int32 ) : width ); | |
| 25 | 24 | writeln( 'high( int64 ) :', high( int64 ) : width ); | |
| 26 | 25 | writeln; | |
| 27 | 26 | writeln( 'variable, depending on target cpu:' ); | |
| 28 | 27 | writeln( '----------------------------------------' ); | |
| 29 | 28 | writeln( 'sizeof( pointer ) :', sizeof( pointer ) : width ); | |
| 30 | 29 | writeln; | |
| 31 | 30 | writeln( 'compile-time definitions:' ); | |
| 32 | 31 | writeln( '----------------------------------------' ); | |
| 33 | 32 | {$IFDEF cpu64} writeln( 'cpu64' ); {$ENDIF} | |
| 34 | 33 | {$IFDEF cpu32} writeln( 'cpu32' ); {$ENDIF} | |
| 35 | 34 | {$IFDEF cpu16} writeln( 'cpu16' ); {$ENDIF} | |
| 36 | 35 | writeln; | |
| 37 | 36 | end. | |
| 38 | 37 | ``` | |
| 39 | 38 | ||
| 40 | 39 | Compare the results with [[Mode TP|-Mtp]] vs [[Mode ObjFPC|-Mobjfpc]], for example: | |
| 41 | 40 | ||
| 42 | 41 | fpc -Mtp maxvals.pas && ./maxvals | |
| 43 | 42 | fpc -Mobjfpc maxvals.pas && ./maxvals | |
| 44 | 43 | ||
| 45 | 44 | --- | |
| 46 | 45 | *From the Free Pascal wiki, page "MaxInt", as it stood on 2023-12-22 after a change by Alextpp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
