Recent

Author Topic: [SOLVED] ssize_t to integer?  (Read 1116 times)

RastaManKing

  • New member
  • *
  • Posts: 15
[SOLVED] ssize_t to integer?
« on: December 29, 2018, 07:28:06 am »
I would like to display a ssize_t value in a Dialog (ShowMessage),
i know i can display an integer with
Code: Pascal  [Select]
  1. IntToStr(myInteger)
but this does not work with the ssize_t variable,
how can i typecast or convert this? i tried
Code: Pascal  [Select]
  1. mySsize_t as integer
but it does not work, i get error saying, class or interface expected but got longint.

Thanks in advance!  :)
« Last Edit: December 29, 2018, 09:16:28 am by RastaManKing »

Thaddy

  • Hero Member
  • *****
  • Posts: 8179
Re: ssize_t to integer?
« Reply #1 on: December 29, 2018, 08:47:01 am »
Code: Pascal  [Select]
  1. {$mode objfpc}
  2. uses unixtype,sysutils;
  3. var
  4.   myinteger:integer = 10;
  5. begin
  6.   writeln(inttostr(ssize_t(myinteger)));
  7. end.
something like that, or
Code: Pascal  [Select]
  1. {$mode objfpc}
  2. uses unixtype,sysutils;
  3. var
  4.   myinteger:integer = 10;
  5. begin
  6.   writeln(ssize_t(myinteger).tostring);
  7. end.
Since ssize_t is a platform integer alias type the cast will use - or expand to - the properly sized integer type.
Also note that size_t is unsigned integer type and ssize_t a signed one.

In most cases the cast would not even be necessary, only if you need the absolute correct size.
Code: Pascal  [Select]
  1. {$mode objfpc}
  2. uses unixtype,sysutils;
  3. var
  4.   mysize_t:ssize_t = 10;
  5. begin
  6.   writeln(mysize_t.tostring);
  7. end.

Because ssize_t is declared an alias to a c integer type which in turn is declared in ctypes as an alias to a pascal integer type of the correct size.
« Last Edit: December 29, 2018, 09:11:05 am by Thaddy »
Read the manuals and if you are a professional get a proper education in computer science. Makes the forum a lot cleaner.

RastaManKing

  • New member
  • *
  • Posts: 15
Re: ssize_t to integer?
« Reply #2 on: December 29, 2018, 09:16:12 am »
In most cases the cast would not even be necessary, only if you need the absolute correct size.
Code: Pascal  [Select]
  1. {$mode objfpc}
  2. uses unixtype,sysutils;
  3. var
  4.   mysize_t:ssize_t = 10;
  5. begin
  6.   writeln(mysize_t.tostring);
  7. end.

Because ssize_t is declared an alias to a c integer type which in turn is declared in ctypes as an alias to a pascal integer type of the correct size.

this one worked, thank you!!
its the only one i hadnt tried, but .tostring worked  ;)