Sign in Join

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

Mailing lists / fpc-pascal / 2012-11

working witg UCS4Char

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

ik

Hello,

I'm trying to work with UCS4Char (for this:
https://github.com/ik5/fp-msgpack), but I can't figure out how to do it.
For example, if do the following:

-------------------------------
{$H+}
uses cwstring;
var
 ch : UCS4Char;
begin
  ch := #$233B4;
  writeln(ch);
end.
-------------------------------

I get the following error:
ppcx64 test.pas
Free Pascal Compiler version 2.6.0 [2012/05/17] for x86_64 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for x86-64
Compiling test.pas
test.pas(8,9) Error: Illegal char constant
test.pas(8,9) Error: Incompatible types: got "Constant String" expected "UCS4Char"
test.pas(11) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted

And if I do it without the hash, then it's just a number

So how can I use it ?

Thanks,
Ido

Reply by email

Jonas Maebe
to ik
ik wrote
And if I do it without the hash, then it's just a number

UCS4Char is in fact just a number, and UCS4String is just a dynamic array of cardinal. UCS4 is not implemented as a complete string type in FPC (or Delphi, for that matter).

Jonas

Reply by email

ik
to Jonas Maebe
Jonas Maebe wrote 9 lines
On 09 Nov 2012, at 16:06, ik wrote: And if I do it without the hash, then it's just a number UCS4Char is in fact just a number, and UCS4String is just a dynamic array of cardinal. UCS4 is not implemented as a complete string type in FPC (or Delphi, for that matter).

Cardinal is a bit problematic type, you mean longword. :)

Thanks

Show quoted text 7 lines
Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Tomas Hajny
to ik
ik wrote 13 lines
On Fri, Nov 9, 2012 at 5:16 PM, Jonas Maebe wrote: > On 09 Nov 2012, at 16:06, ik wrote: > > And if I do it without the hash, then it's just a number > > > UCS4Char is in fact just a number, and UCS4String is just a dynamic > array of > cardinal. UCS4 is not implemented as a complete string type in FPC (or > Delphi, for that matter). Cardinal is a bit problematic type, you mean longword. :)

Why do you see cardinal as a "problematic type"? At least for FPC it is a simple alias to longword (and it has actually existed even before longword in FPC).

Tomas

Reply by email

ik
to Tomas Hajny
Tomas Hajny wrote 18 lines
On Fri, November 9, 2012 17:01, ik wrote: > On Fri, Nov 9, 2012 at 5:16 PM, Jonas Maebe > wrote: >> On 09 Nov 2012, at 16:06, ik wrote: >> >> And if I do it without the hash, then it's just a number >> >> >> UCS4Char is in fact just a number, and UCS4String is just a dynamic >> array of >> cardinal. UCS4 is not implemented as a complete string type in FPC (or >> Delphi, for that matter). > > Cardinal is a bit problematic type, you mean longword. :) Why do you see cardinal as a "problematic type"? At least for FPC it is a simple alias to longword (and it has actually existed even before longword in FPC).

At least with Delphi it has unclear what exactly the size of it. And the following code:
https://github.com/ik5/fp-msgpack/blob/master/src/msgpack.pas#L528

Used to be with Cardinal (the only difference), and It never acted as expected. The only thing I changed was from cardinal to longword, and it acts as expected.

Show quoted text 7 lines
Tomas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Tomas Hajny
to ik
ik wrote 30 lines
On Fri, Nov 9, 2012 at 6:12 PM, Tomas Hajny wrote: > On Fri, November 9, 2012 17:01, ik wrote: >> On Fri, Nov 9, 2012 at 5:16 PM, Jonas Maebe >> wrote: >>> On 09 Nov 2012, at 16:06, ik wrote: >>> >>> And if I do it without the hash, then it's just a number >>> >>> >>> UCS4Char is in fact just a number, and UCS4String is just a dynamic >>> array of >>> cardinal. UCS4 is not implemented as a complete string type in FPC (or >>> Delphi, for that matter). >> >> Cardinal is a bit problematic type, you mean longword. :) > > Why do you see cardinal as a "problematic type"? At least for FPC it is > a > simple alias to longword (and it has actually existed even before > longword > in FPC). At least with Delphi it has unclear what exactly the size of it. And the following code: https://github.com/ik5/fp-msgpack/blob/master/src/msgpack.pas#L528 Used to be with Cardinal (the only difference), and It never acted as expected. The only thing I changed was from cardinal to longword, and it acts as expected.

With Delphi or with FPC? As already mentioned, FPC defines cardinal as an alias to longword (and UInt32 mentioned in your reference as an alias to cardinal) so there should be no difference between cardinal, longword and UInt32 (and in the past, cardinal was even the primary type in FPC directly known by the compiler).

With Delphi, I believe that very old Delphi versions defined cardinal as a 31-bit type (i.e. simply the non-negative part of the longint range), but I also believe (while not using Delphi at all myself) that all currently relevant Delphi versions (i.e. not considering things like Delphi 1.0 and Delphi 2.0 which probably didn't support longword anyway) define cardinal as equal to longword.

Tomas

Reply by email

ik
to Tomas Hajny
Tomas Hajny wrote 44 lines
On Fri, November 9, 2012 17:38, ik wrote: > On Fri, Nov 9, 2012 at 6:12 PM, Tomas Hajny wrote: >> On Fri, November 9, 2012 17:01, ik wrote: >>> On Fri, Nov 9, 2012 at 5:16 PM, Jonas Maebe >>> wrote: >>>> On 09 Nov 2012, at 16:06, ik wrote: >>>> >>>> And if I do it without the hash, then it's just a number >>>> >>>> >>>> UCS4Char is in fact just a number, and UCS4String is just a dynamic >>>> array of >>>> cardinal. UCS4 is not implemented as a complete string type in FPC (or >>>> Delphi, for that matter). >>> >>> Cardinal is a bit problematic type, you mean longword. :) >> >> Why do you see cardinal as a "problematic type"? At least for FPC it is >> a >> simple alias to longword (and it has actually existed even before >> longword >> in FPC). > > At least with Delphi it has unclear what exactly the size of it. > And the following code: > https://github.com/ik5/fp-msgpack/blob/master/src/msgpack.pas#L528 > > Used to be with Cardinal (the only difference), and It never acted as > expected. > The only thing I changed was from cardinal to longword, and it acts as > expected. With Delphi or with FPC? As already mentioned, FPC defines cardinal as an alias to longword (and UInt32 mentioned in your reference as an alias to cardinal) so there should be no difference between cardinal, longword and UInt32 (and in the past, cardinal was even the primary type in FPC directly known by the compiler). With Delphi, I believe that very old Delphi versions defined cardinal as a 31-bit type (i.e. simply the non-negative part of the longint range), but I also believe (while not using Delphi at all myself) that all currently relevant Delphi versions (i.e. not considering things like Delphi 1.0 and Delphi 2.0 which probably didn't support longword anyway) define cardinal as equal to longword.

With FPC. The value was saved wrong.
The only thing that I changed in my code was moving from Cardinal to LongWord.

I do not own Delphi or Windows copy for many years now :)

Show quoted text 7 lines
Tomas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Tomas Hajny
to ik
ik wrote
On Fri, Nov 9, 2012 at 6:56 PM, Tomas Hajny wrote: > On Fri, November 9, 2012 17:38, ik wrote: >> On Fri, Nov 9, 2012 at 6:12 PM, Tomas Hajny wrote: >>> On Fri, November 9, 2012 17:01, ik wrote:

.
.

Show quoted text 22 lines
>>>> Cardinal is a bit problematic type, you mean longword. :) >>> >>> Why do you see cardinal as a "problematic type"? At least for FPC it is >>> a >>> simple alias to longword (and it has actually existed even before >>> longword >>> in FPC). >> >> At least with Delphi it has unclear what exactly the size of it. >> And the following code: >> https://github.com/ik5/fp-msgpack/blob/master/src/msgpack.pas#L528 >> >> Used to be with Cardinal (the only difference), and It never acted as >> expected. >> The only thing I changed was from cardinal to longword, and it acts as >> expected. > > With Delphi or with FPC? As already mentioned, FPC defines cardinal as an > alias to longword (and UInt32 mentioned in your reference as an alias to > cardinal) so there should be no difference between cardinal, longword and > UInt32 (and in the past, cardinal was even the primary type in FPC > directly known by the compiler).

.
.

With FPC. The value was saved wrong. The only thing that I changed in my code was moving from Cardinal to LongWord.

.
.

Sorry, but I cannot imagine how this could happen considering that one of them is alias to the other and thus they cannot be treated differently by the compiler (you can even interchange them for actual parameters and the compiler wouldn't notice it). If you have a short test showing otherwise, please post a bug report.

Tomas

Reply by email