Skip to content

PPChar type seems to be incorrect for {$MODESWITCH UNICODESTRINGS}

Summary

When using {$MODESWITCH UNICODESTRINGS}, type PPChar doesn't work as expected.

System Information

  • Operating system: Windows
  • Processor architecture: x86, x86_64
  • Compiler version: 3.2.2
  • Device: Computer

Steps to reproduce

program test;

{$MODE OBJFPC}
{$MODESWITCH UNICODESTRINGS}

var
  S: string;
  pS: PChar;
  ppS: PPChar;

begin
  S := 'test string';
  pS := @S[1];
  ppS := @pS;
  pS := ppS^;  // Error: Incompatible types: got "PChar" expected "PWideChar"
  WriteLn(string(pS));
end.

What is the current bug behavior?

See above comment line.

What is the expected (correct) behavior?

With {$MODESWITCH UNICODESTRINGS}, PPChar should be ^PChar.

Possible fixes

Can fix above code by adding:

type
  PPChar = ^PChar;
Edited by Bill Stewart
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information