Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-10

Cardinal = LongWord on 64bit systems?

7 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Based on the FPC documentation for integer types, is says that a Cardinal type can be either word, longword or qword (sizes being 2, 4, 8 bytes) based on the platform used.

So why on my 64bit system using FPC 2.3.1, Cardinal maps to a LongWord. Shouldn't that be QWord for 64bit systems? Just like PtrUint maps to QWord on 64bit platforms, but to LongWord for 32bit platforms

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 5 lines
Hi, Based on the FPC documentation for integer types, is says that a Cardinal type can be either word, longword or qword (sizes being 2, 4, 8 bytes) based on the platform used.

Where do you see that ? Not in my docs ?

Show quoted text 5 lines
So why on my 64bit system using FPC 2.3.1, Cardinal maps to a LongWord. Shouldn't that be QWord for 64bit systems? Just like PtrUint maps to QWord on 64bit platforms, but to LongWord for 32bit platforms

Cardinal is always 32-bit ?

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
Where do you see that ? Not in my docs ?

Ah, I was viewing an old v2.0.2 ref.pdf document. I see the newer ref.pdf (Table 3.2) is now different and clearly mentions that Cardinal is always a 32bit type (LongWord). I'll make sure I delete all old FPC pdf documents lying around to not make that mistake again.

So if I want to use a unsigned integer (pointer) type and be correct on each platform, must I use the ValUInt type instead? See my GetMem/FreeMem thread for an example.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 12 lines
On 15/10/2009, Michael Van Canneyt wrote: > > Where do you see that ? Not in my docs ? Ah, I was viewing an old v2.0.2 ref.pdf document. I see the newer ref.pdf (Table 3.2) is now different and clearly mentions that Cardinal is always a 32bit type (LongWord). I'll make sure I delete all old FPC pdf documents lying around to not make that mistake again. So if I want to use a unsigned integer (pointer) type and be correct on each platform, must I use the ValUInt type instead? See my GetMem/FreeMem thread for an example.

PtrUInt

About PLong: use unit ctypes: PCLong

Mattias

Reply by email

Graeme Geldenhuys
to Mattias Gaertner
Mattias Gaertner wrote
PtrUInt

So what is the difference between PtrUint and ValUInt? Where would you use each?

About PLong: use unit ctypes: PCLong

I'm trying to minimize the amount of "new" types introduced in this ported project. I already have so many custom types like shown below. So I would prefer to convert these custom types to actually (included by default) types available in FPC.

// used by header translation from C -> Object Pascal
type
  uint32  = longword;
  uint16  = word;
  uint8   = byte;
  pUInt16 = ^uint16;
  pUInt32 = ^uint32;
  pUInt8  = ^uint8;
Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Henrick Hellström
Graeme Geldenhuys wrote 7 lines
On 15/10/2009, Mattias Gaertner wrote: > PtrUInt > So what is the difference between PtrUint and ValUInt? Where would you use each?

* Use PtrUInt when casting pointers to integers and back.
* Use ValUInt when performing operations that would benefit from using the largest integer type supported by the CPU. For instance, if you are going to xor a large chunk of memory with a constant bit pattern, it is most efficient to treat that memory as an array of ValUInt.

Reply by email

Marco van de Voort
to Graeme Geldenhuys: So what is the difference between PtrUint and ValUInt? Where would you use each? I'm…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 15 lines
> About PLong: use unit ctypes: PCLong I'm trying to minimize the amount of "new" types introduced in this ported project. I already have so many custom types like shown below. So I would prefer to convert these custom types to actually (included by default) types available in FPC. // used by header translation from C -> Object Pascal type uint32 = longword; uint16 = word; uint8 = byte; pUInt16 = ^uint16; pUInt32 = ^uint32; pUInt8 = ^uint8;

All of these are in ctypes with a c prefixed (cuint* and pcuint*), corresponding to the local system C compiler. (rep. gcc or MSVC)

Reply by email