SRL Archive - General

longword, cardinal, dword, uint32...


riwu

2014-10-26 05:26:48

Aren't they the exact same thing? Why is there a need to create so many alias to represent the same data type?

Brandon

2014-10-26 10:32:36

From: riwu
Aren't they the exact same thing? Why is there a need to create so many alias to represent the same data type?


I don't know about pascal but some of those types aren't guaranteed in the C and C++ standard.


longword is the same as dword. It really is just an alias.
Dword is an alias for unsigned int.

however, unsigned int is never guaranteed to be 4 bytes always. The sizeof(int) is actually implementation defined but must be greater than or equal to "2".

In fact, in the old days, vendors used to define int as 2 bytes on some systems and 4 on others.. sometimes even 8. This meant that you had to manually deal with endianness yourself and hardcode sizes in some places.

Nowadays, most vendors define int to always be 4 bytes but that doesn't mean old systems don't still exist..

The only guaranteed type there is "uint32" which in C and C++ is defined as "uint32_t" where the "t" means typedef/alias.
But the standard guarantees that this type is ALWAYS 4 bytes in size. Never larger; never smaller.

It is especially useful in very very low level code as well as embedded systems..

http://en.cppreference.com/w/c/types/integer
http://en.cppreference.com/w/cpp/types/integer

But I doubt it has any effect in PS/Lape.. so I don't know why they have that many but if it is the same as in C, then the above is the reason. If I had to really really guess, I'd say these types are mostly used for plugin compatibility..

slacky

2014-10-26 16:28:12

From: Brandon
so I don't know why they have that many … I'd say these types are mostly used for plugin compatibility..

Lape's (integer) basetypes are named IntX and UIntX (IE: Int16 & UInt64), other (integer) types are aliases, and mostly exists for compatibility with PascalScript, as PascalScript does NOT have IntX + UIntX named-types.

References:
» Lape -> lputils.pas #49
» Lape -> lpvartypes.pas #718 (lptypes.pas #150)

DWord is exported by Simba, and I do not know why.. I guess it's just because it's "standard":
» https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLAddon/LPInc/lpcompile.inc#L83

riwu

2014-10-27 12:20:52

i see… thanks for the explanation :)