Re: [fpc-pascal] History of the Cardinal data type?
On Tue, Mar 29, 2016 at 9:06 PM, Graeme Geldenhuys < mailingli...@geldenhuys.co.uk> wrote: > So I definitely see the benefit in using (U)Int style data types. > They are a lot more obvious [to the programmer] regarding data ranges > and byte size. > Does, it also make the code less high-level? Didn't high level use the platform independent notation such as "int" or "word" to be portable across different platforms back in 60s 70s? At that time word size might vary dramatically from system to system ( https://en.wikipedia.org/wiki/Word_(computer_architecture) ) Thus a code written like this: a: Int32; would not be portable, since it requires a target platform to support 32-bit word (or at least the compiler had to be smart enough). The modern generation of developers doesn't really have to deal with that too much, due to dominance of 32-bit (as well as virtual machines, such as java and/or .net). But jump to 64-bit still caused a bit of confusion (in C/C++ and object pascal). with type names and sizes. thanks, Dmitry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
Thanks Marco, interesting history lesson. ;-) On 2016-03-29 22:16, Marco van de Voort wrote: > Moreover since shorter types are not always faster, I think it is better to > forget all this, and in new code use INTEGER for the variable types, where > range doesn't matter (much) and (u)int for the rest. I already tend to use Integer for most code, but the code I'm currently working on has an extensive amount of record structures used to read a complex binary data file. The documentation for the data file is primarily in C and uses types like SHORT, USHORT, LONG etc. These translated easily to the SmallInt, Word, LongWord etc types, but as already mentioned in can get confusing keeping track of valid ranges and occasional programmer error. So I definitely see the benefit in using (U)Int style data types. They are a lot more obvious [to the programmer] regarding data ranges and byte size. I was just surprised not to find any reference to them in the FPC documentation. I already made personal annotations about them so as not to be forgotten, but I think it will be beneficial to have them officially included in the FPC Language Reference too. After all, they are part of the System unit. Here is an example of the annotation I added to my own documentation. Type Range Size in bytes Int8 = ShortInt-128 .. 127 1 Int16 = SmallInt -32768 .. 32767 2 Int32 = LongInt -2147483648 .. 2147483647 4 Int64-9223372036854775808 .. 9223372036854775807 8 UInt8 = Byte 0 .. 255 1 UInt16 = Word 0 .. 65535 2 UInt32 = Cardinal 0 .. 4294967295 4 UInt64 = QWord 0 .. 184467440737095516158 Regards, - Graeme - ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
In our previous episode, Nikolay Nikolov said: > compatible, changing Cardinal to 16-bit does more harm that good. Many > FPC demos, such as fpctris and samegame now run unmodified on > i8086-msdos. (that's because parts of them, specially gameunit, have M2 origins) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
In our previous episode, Sven Barth said: > > types with fields of type Word, Smallint etc, than then some Cardinal > > fields got mixed in too. I would normally use LongWord instead of > > Cardinal to keep to a consistent naming convention. But from your > > comments Cardinal has a long history in Pascal. > > I usually use LongWord, too, but with the recent discovery that in Delphi > LongWord is not always 32-bit (and my tendency to confuse Short and > SmallInt) I'm inclined to use the (U)IntX (with X being a element of [8, > 16, 32, 64]) types to avoid any confusion and surprises. Apparently Embarcadero knew that too, since (with iirc XE2) they added all variants to Delphi. FPC supports this for some releases already too (and longer in ctypes) I always found specially small and short very confusing so I adopted it early. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On 03/29/2016 06:13 PM, Marco van de Voort wrote: In our previous episode, Graeme Geldenhuys said: Just curious. What is the history behind the Cardinal data type. As per the FPC documentation, it is always mapped to the LongWord type. I presume it is the same in Delphi. Cardinal is the Wirthian designation for the default unsigned integer, just like "integer" is for signed. The Delphi side of things is more convoluted because pre-int64 Delphis had 31-bits Cardinals. Even more so, Delphi 1 was 16-bit and its Cardinal type was 16-bit (i.e. equal to the "Word" type) With Delphi 2 (the first 32-bit Delphi), Cardinal became 32-bit (31-bit, actually, as Marco said). So, back then it was a CPU-specific unsigned integer type (just like "Integer" is the signed version). Note that even though FPC now also supports 16-bit x86 CPUs, Cardinal is still 32-bit unsigned there. Even though this is not Delphi 1 compatible, changing Cardinal to 16-bit does more harm that good. Many FPC demos, such as fpctris and samegame now run unmodified on i8086-msdos. If we changed the Cardinal type to 16-bit, they would break and require changes in order to work. And most 16-bit code that is likely to be ported to FPC is coming from Turbo Pascal, which didn't have Cardinal (only "Word", which is always 16-bit), so we don't really follow the convention that Cardinal is a platform specific type. So, in FPC it is fixed to 32-bit unsigned on all platforms and in all compiler modes. Nikolay ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
Hi Michael, On 2016-03-29 16:18, Michael Van Canneyt wrote: > Longword used to be Cardinal. > I guess it was changed for Delphi compatibility. I really like Sven's idea of using (U)IntX data types where X is 8, 16, 32 or 64 bit. I think this is also future proof, considering Delphi's data type mess and the fact that FPC likes to be FPC compatible. With that being said, I noticed the FPC Language Reference doesn't mention the (U)IntX data types at all. Would it not maybe be useful in updating Tables 3.1 & 3.2 with the (U)IntX data types? http://www.freepascal.org/docs-html/ref/refsu5.html Or maybe add a new table that shows the mapping between (U)IntX and other Object Pascal types and what range they apply to (similar to Table 3.2). eg: Int16 = SmallInt UInt16 = Word Int32 = Cardinal = LongWord etc. I don't mind supplying a documentation patch for you to review. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On 2016-03-29 20:19, Sven Barth wrote: > > I usually use LongWord, too, My preference is based on the fact that they often translate nicely from C code examples and APIs. Plus I know those types and sizes pretty well (at least when in comes to Free Pascal). > but with the recent discovery that in Delphi Luckily Delphi is of no concern to me. :) > I'm inclined to use the (U)IntX (with X being a element of [8, > 16, 32, 64]) types to avoid any confusion and surprises. That's not a bad idea either... I'll look into that for future code. Regards, - Graeme - ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
Am 29.03.2016 17:27 schrieb "Graeme Geldenhuys" < mailingli...@geldenhuys.co.uk>: > > On 2016-03-29 16:13, Marco van de Voort wrote: > > Cardinal is the Wirthian designation for the default unsigned integer, > > just like "integer" is for signed. > > Thanks Marco, that fulfils my curiosity. :) > > > On a side note: > The reason I asked this question. I'm working on code with many Record > types with fields of type Word, Smallint etc, than then some Cardinal > fields got mixed in too. I would normally use LongWord instead of > Cardinal to keep to a consistent naming convention. But from your > comments Cardinal has a long history in Pascal. I usually use LongWord, too, but with the recent discovery that in Delphi LongWord is not always 32-bit (and my tendency to confuse Short and SmallInt) I'm inclined to use the (U)IntX (with X being a element of [8, 16, 32, 64]) types to avoid any confusion and surprises. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On Tue, Mar 29, 2016 at 11:31 AM, Graeme Geldenhuys < mailingli...@geldenhuys.co.uk> wrote: > On 2016-03-29 16:17, Dmitry Boyarintsev wrote: > > In Delphi world LongWord is 64-bit on 64-bit iOS platform and it is > 32-bit > > on 64-bit Windows platform. > > So what happened when they introduced Android support? Yet another > definition or copied one of the others? > >From what I can see they currently support 32-bit processors for Android devices. ( http://docwiki.embarcadero.com/RADStudio/Seattle/en/Android_Devices_Supported_for_Application_Development ) So Cardinal is still 32-bit there. I'd think it will grow to 64-bit as soon as arm64 is supported. thanks, Dmitry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On 2016-03-29 16:13, Marco van de Voort wrote: > Cardinal is the Wirthian designation for the default unsigned integer, > just like "integer" is for signed. Thanks Marco, that fulfils my curiosity. :) On a side note: The reason I asked this question. I'm working on code with many Record types with fields of type Word, Smallint etc, than then some Cardinal fields got mixed in too. I would normally use LongWord instead of Cardinal to keep to a consistent naming convention. But from your comments Cardinal has a long history in Pascal. Regards, - Graeme - ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On 2016-03-29 16:17, Dmitry Boyarintsev wrote: > In Delphi world LongWord is 64-bit on 64-bit iOS platform and it is 32-bit > on 64-bit Windows platform. So what happened when they introduced Android support? Yet another definition or copied one of the others? Regards, - Graeme - ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On Tue, Mar 29, 2016 at 11:20 AM, Michael Van Canneyt < mich...@freepascal.org> wrote: > > Which is quite confusing and a really bad decision. > Basic integer types should not depend on the OS. On the CPU, yes. > > I guess they tried to make iOS platform a selling point and be more C-like. Just to remember that Strings are zero-based there, by default. I believe this came with anticipation that the platform will not use (much) of existing code base. thanks, Dmitry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On 2016-03-29 16:17, Dmitry Boyarintsev wrote: > In Delphi world LongWord is 64-bit on 64-bit iOS platform and it is 32-bit > on 64-bit Windows platform. > > http://docwiki.embarcadero.com/RADStudio/XE8/en/What's_New#Changes_in_LongInt_and_LongWord_Size_for_64-bit_iOS_Platforms > Wow, that sounds like a terrible idea. I fully agree with Michael's statement - data type sizes should not be based on OS, but on CPU. Regards, - Graeme - ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On Tue, 29 Mar 2016, Dmitry Boyarintsev wrote: On Tue, Mar 29, 2016 at 11:06 AM, Graeme Geldenhuys < mailingli...@geldenhuys.co.uk> wrote: So why does the Object Pascal language have a Cardinal type? Why couldn't LongWord be used instead? In Delphi world LongWord is 64-bit on 64-bit iOS platform and it is 32-bit on 64-bit Windows platform. Which is quite confusing and a really bad decision. Basic integer types should not depend on the OS. On the CPU, yes. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On Tue, 29 Mar 2016, Graeme Geldenhuys wrote: Hi, Just curious. What is the history behind the Cardinal data type. As per the FPC documentation, it is always mapped to the LongWord type. I presume it is the same in Delphi. It used to be opposite, if I recall correctly. Longword used to be Cardinal. I guess it was changed for Delphi compatibility. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
On Tue, Mar 29, 2016 at 11:06 AM, Graeme Geldenhuys < mailingli...@geldenhuys.co.uk> wrote: > So why does the Object Pascal language have a Cardinal type? Why > couldn't LongWord be used instead? > In Delphi world LongWord is 64-bit on 64-bit iOS platform and it is 32-bit on 64-bit Windows platform. http://docwiki.embarcadero.com/RADStudio/XE8/en/What's_New#Changes_in_LongInt_and_LongWord_Size_for_64-bit_iOS_Platforms Who know what it would be for future Linux 64 target?! Thus using LongWord as 32-bit for Delphi is quite volatile. Cardinal is instead always 32-bit http://docwiki.embarcadero.com/Libraries/XE8/en/System.Cardinal thanks, Dmitry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] History of the Cardinal data type?
In our previous episode, Graeme Geldenhuys said: > Just curious. What is the history behind the Cardinal data type. As per > the FPC documentation, it is always mapped to the LongWord type. I > presume it is the same in Delphi. Cardinal is the Wirthian designation for the default unsigned integer, just like "integer" is for signed. The Delphi side of things is more convoluted because pre-int64 Delphis had 31-bits Cardinals. > So why does the Object Pascal language have a Cardinal type? Why > couldn't LongWord be used instead? See above. Variable size type vs fixed size type. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] History of the Cardinal data type?
Hi, Just curious. What is the history behind the Cardinal data type. As per the FPC documentation, it is always mapped to the LongWord type. I presume it is the same in Delphi. So why does the Object Pascal language have a Cardinal type? Why couldn't LongWord be used instead? Regards, - Graeme - ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to crosscompile i386-linux from X86_64-win64
Am 29.03.2016 10:30 schrieb "Jonas Maebe": > > On 29/03/16 09:58, ulrich wrote: >> >> what parameter(s) need to cross-compiling i386-Linux from X86_64-win64 ? > > > It is not possible, because the needed 80 bits extended type is not supported on Win64, and we don't have emulation for this type yet in the compiler. You can follow http://bugs.freepascal.org/view.php?id=9262 if you wish to be notified in case this ever gets implemented. > However on Windows there's no real penalty in using the i386-win32 release for this instead of the x86_64-win64 one. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to crosscompile i386-linux from X86_64-win64
On 29/03/16 09:58, ulrich wrote: what parameter(s) need to cross-compiling i386-Linux from X86_64-win64 ? It is not possible, because the needed 80 bits extended type is not supported on Win64, and we don't have emulation for this type yet in the compiler. You can follow http://bugs.freepascal.org/view.php?id=9262 if you wish to be notified in case this ever gets implemented. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] How to crosscompile i386-linux from X86_64-win64
Hi, what parameter(s) need to cross-compiling i386-Linux from X86_64-win64 ? When I am trying to compile from "win32" with win32 compiler: c:\Lazarus16\fpc\3.0.0\bin\x86_64-win64\make.exe CROSSCOMPILE=1 CPU_TARGET=i386 OS_TARGET=linux all CROSSBINUTILS=c:\lazarus16\fpc\3.0.0\bin\i386-linux BINUTILSPREFIX=i386-linux- CPU_SOURCE=i386 OS_SOURCE=win32 FPC=c:\lazarus16\fpc\3.0.0\bin\i386-win32\fpc.exe the result is: make[4]: Entering directory `C:/lazarus16/fpc/3.0.0/rtl' c:/lazarus16/fpc/3.0.0/bin/x86_64-win64/make -C win32 all make[5]: Entering directory `C:/lazarus16/fpc/3.0.0/rtl/win32' c:/lazarus16/fpc/3.0.0/bin/i386-win32/fpc.exe -Ur -Xs -O2 -n -Fi../inc -Fi../i386 -Fi../win -FE. -FUC:/lazarus16/fpc/3.0.0/rtl/units/i386-win32 -di386 -dRELEASE -Us -Sg system.pp -Fi../win systemh.inc(138,16) Error: Duplicate identifier "FarPointer" systemh.inc(138,29) Error: Identifier not found "NearFsPointer" systemh.inc(138,29) Error: Error in type definition systemh.inc(1059,75) Error: Type "FarPointer" is not completely defined system.pp(107,34) Fatal: There were 4 errors compiling module, stopping Fatal: Compilation aborted Error: c:\lazarus16\fpc\3.0.0\bin\i386-win32\ppc386.exe returned an error exitcode make[5]: *** [system.ppu] Error 1 make[5]: Leaving directory `C:/lazarus16/fpc/3.0.0/rtl/win32' make[4]: *** [win32_all] Error 2 make[4]: Leaving directory `C:/lazarus16/fpc/3.0.0/rtl' make[3]: *** [rtl] Error 2 make[3]: Leaving directory `C:/lazarus16/fpc/3.0.0/compiler' make[2]: *** [cycle] Error 2 make[2]: Leaving directory `C:/lazarus16/fpc/3.0.0/compiler' make[1]: *** [compiler_cycle] Error 2 make[1]: Leaving directory `C:/lazarus16/fpc/3.0.0' make: *** [build-stamp.i386-linux] Error 2 When I am trying to compile from "win64" with win64 compiler (X86_64): c:\lazarus16\fpc\3.0.0\bin\x86_64-win64\make.exe CROSSCOMPILE=1 CPU_TARGET=i386 OS_TARGET=linux all CROSSBINUTILS=c:\lazarus16\fpc\3.0.0\bin\i386-linux BINUTILSPREFIX=i386-linux- the result is: C:/lazarus16/fpc/3.0.0/compiler/ppc.exe -Ur -Xs -O2 -n -Fui386 -Fusystems -FuC:/lazarus16/fpc/3.0.0/rtl/units/x86_64-win64 -Fii386 -FE. -FUi386/units/x86_64-win64 -dRELEASE -di386 -dGDB -dBROWSERLOG -Fux86 -Sew pp.pas fpcdefs.inc(259,2) Error: User defined: Cross-compiling from systems without support for an 80 bit extended floating point type to i386 is not yet supported at this time fpcdefs.inc(259,2) Error: User defined: Cross-compiling from systems without support for an 80 bit extended floating point type to i386 is not yet supported at this time fpcdefs.inc(259,2) Error: User defined: Cross-compiling from systems without support for an 80 bit extended floating point type to i386 is not yet supported at this time fpcdefs.inc(259,2) Error: User defined: Cross-compiling from systems without support for an 80 bit extended floating point type to i386 is not yet supported at this time constexp.pas(87,1) Fatal: There were 4 errors compiling module, stopping Fatal: Compilation aborted make[3]: *** [ppcross386.exe] Error 1 make[3]: Leaving directory `C:/lazarus16/fpc/3.0.0/compiler' make[2]: *** [cycle] Error 2 make[2]: Leaving directory `C:/lazarus16/fpc/3.0.0/compiler' make[1]: *** [compiler_cycle] Error 2 make[1]: Leaving directory `C:/lazarus16/fpc/3.0.0' make: *** [build-stamp.i386-linux] Error 2 Thanks Ulrich ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal