Recent

Author Topic: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)  (Read 16033 times)

xaero

  • New member
  • *
  • Posts: 9
I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« on: May 23, 2010, 03:49:33 am »
Code: [Select]
programe test;
var a:integer;
begin
    a:=40000;
    writeln(pred(a));
end.

In Lazarus,this will output 39999!!!
but actually "a" is an integer, can't take 40000!
how to Correct it???


Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #1 on: May 23, 2010, 04:33:29 am »
An integer has no predefined size. FPC uses 32bit or 16bit (http://lazarus-ccr.sourceforge.net/docs/rtl/objpas/integer.html). If you want to ensure 16bit signed respectively a range from -32,768 to +32,767 use "smallint".

http://en.wikipedia.org/wiki/Integer_%28computer_science%29

One punctuation mark is enough.
Lazarus 1.7 (SVN) FPC 3.0.0

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12255
  • FPC developer.
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #2 on: May 23, 2010, 08:23:45 am »
Code: [Select]
programe test;
var a:integer;
begin
    a:=40000;
    writeln(pred(a));
end.

In Lazarus,this will output 39999!!!
but actually "a" is an integer, can't take 40000!

Check your settings and compiler mode, and make sure it is a TP-like mode (TP or FPC), and not a delphi like mode that has integer=32-bit. (objfpc, delphi)

I tested your code and prints

[Turtle] </home/marcov/testing> ./test
-25537

if compiled with the proper mode,

xaero

  • New member
  • *
  • Posts: 9
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #3 on: May 23, 2010, 10:49:16 pm »
Thanks !

and how to make FPC mode as the default setting?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8814
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #4 on: May 24, 2010, 02:02:09 am »
Quote
and how to make FPC mode as the default setting?
It's in compiler options.

stonefull

  • Jr. Member
  • **
  • Posts: 54
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #5 on: May 24, 2010, 11:35:25 am »
Change mode on:

{$mode fpc}{$H+}

Code: [Select]
program inteiro;

{$mode fpc}{$H+}  // change mode here

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };
var
  a: integer;
{$R *.res}

begin
  a := 40000;
  writeln(pred(a));
  readln;
end.         

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12255
  • FPC developer.
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #6 on: May 24, 2010, 04:43:50 pm »
FPC mode is the default, without $mode directives or -Sd/-S2 etc cmdline parameters

xaero

  • New member
  • *
  • Posts: 9
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #7 on: May 24, 2010, 09:10:35 pm »
Many thanks !

But in my Lazarus(v0.9.28.2), Object Pascal(-Mobjfpc) is the default!

with Project --> Complier Option menu , I can set FPC(-Mfpc) as the current project's complier mode
but when I create another new project, it automaticly changes to the default complier(-Mobjfpc)!!!!

how to change the complier mode of  every project i create to FPC(-Mfpc)? (I don't like write the code "{$mode fpc}" etc in every project)

mas steindorff

  • Hero Member
  • *****
  • Posts: 555
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #8 on: May 24, 2010, 11:16:16 pm »
just so you know, you are going about this integer resizing all wrong.  the define of an integer is to be system and OS dependant.  it should change with the upcoming 64 bit OS.  it would be best to define a variable to be the size you wish like this

Type
  S8 = ShortInt;
  U8 = byte;
  chr8 = ANSIChar;  // or char
  S16 = SmallInt;
  U16 = word;
  S32 = LongInt;
  U32 = Cardinal;
  F32 = single;
  F64 = Double;

Then you only have one place to change if any of the types get promoted. this type define can be inside some os dependant ifdefs as well for more portability
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #9 on: May 25, 2010, 02:07:54 am »
how to change the complier mode of  every project i create to FPC(-Mfpc)? (I don't like write the code "{$mode fpc}" etc in every project)
It's not supported for now to select "a default mode".

But you don't need to write {$mode fpc} in every unit or project. Just change the  Project -> Complier Options -> Syntax Mode option on each project created. The mode would be used for all compiled units (without explicit {$mode xxx} setting).


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12255
  • FPC developer.
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #10 on: May 25, 2010, 06:02:56 am »
  it should change with the upcoming 64 bit OS. 

(no it doesn't)
 

xaero

  • New member
  • *
  • Posts: 9
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #11 on: May 25, 2010, 08:13:47 am »
thanks, Moderator
thanks everyone

genomega

  • Newbie
  • Posts: 1
Re: I want Integer, NOT the longint! (with Lazarus 0.9.28.2)
« Reply #12 on: June 05, 2010, 04:51:44 pm »
Found this answer searching, thanks.  :)

 

TinyPortal © 2005-2018