Recent

Author Topic: can writeln output null terminated wide character arrays ?  (Read 2421 times)

440bx

  • Hero Member
  • *****
  • Posts: 3946
can writeln output null terminated wide character arrays ?
« on: July 09, 2018, 04:45:48 am »
Hello,

The following works fine

Code: Pascal  [Select][+][-]
  1. var
  2.    anarrowstring : pchar = 'this is a "narrow" string';
  3. ...
  4. begin
  5.    writeln(anarrowstring);
  6. end.
  7.  
The compiler is, as expected, perfectly happy with that.  On the other hand, if pchar is changed to pwidechar, the compiler emits an error stating that variables of that type can neither be read nor written.  e,g.  the following does not work :


Code: Pascal  [Select][+][-]
  1. var
  2.    awidestring : pwidechar = 'this is a "wide" string';
  3. ...
  4. begin
  5.    writeln(awidestring);
  6. end.
  7.  

Did I miss something or is it really the case that writeln cannot write wide characters to the console ?   I can always import wprintf from user32.dll but, I'd rather keep things "pascal" if possible.

Thank you for your help.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: can writeln output null terminated wide character arrays ?
« Reply #1 on: July 09, 2018, 07:05:09 am »
Cast to unicodestring?

Code: Pascal  [Select][+][-]
  1. program untitled;
  2. var
  3.    awidestring : pwidechar = 'this is a "wide" string';
  4.  
  5. begin
  6.    writeln(unicodestring(awidestring));
  7. end.
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: can writeln output null terminated wide character arrays ?
« Reply #2 on: July 09, 2018, 06:19:44 pm »
That works :D.  Thank you Thaddy.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018