View Issue Details

IDProjectCategoryView StatusLast Update
0016219FPCCompilerpublic2010-11-16 16:57
ReporterThierry Coq Assigned ToJonas Maebe  
Status closedResolutionfixed 
Product Version2.4.1 
Fixed in Version2.6.0 
Summary0016219: String in const array of string does not compile
DescriptionThe following piece of code results in a compiler abort with the following message: Fatal: Compilation aborted.


  aStrArray: array [0..0] of String = (

    #$ffff' '


The same string in a const, without the array, compiles:
  aStrArray: #$ffff' ';

If the $ffff is the last part of the string, it compiles?

Steps To ReproduceTake the piece of code above and put it in a simple program. Compile. The compilation will abort.

A Lazarus project reproducing the problem is attached.
Additional InformationThis was also tested as a bug on 2.3.1.
However in Linux, I was unable to reproduce the bug (FPC 2.4.0, Build 22279, 25-10-2009).

A work-around for me that worked was to declare a (long) list of string constants, each with a different name.

TagsNo tags attached.
Fixed in Revision15240
Attached Files


has duplicate 0018140 resolvedJonas Maebe Initialized variables string with utf8 


2010-04-07 07:44 (424,109 bytes)

Bart Broersma

2010-04-07 11:58

reporter   ~0036514

fpc 2.4.1 / Win9x

With {$H-} when compiling I get a warning:

strarray.pp(9,3) Warning: string "`~Z" is longer than "255"

writeln('>',aStrArray[0],'<') gives:
>`~Z # ,Á_
           P  \q?  ü £pDîZ 
                                            <¦_    P  Ó­)<
¦_  ü <

If you declare
  aStrArray: #$ffff' ';
no such warning is shown and writeln('>',aStr,'<') gives >? <

With {$H+} compiling fails and the compiler crashes:

Free Pascal Compiler version 2.4.1 [2010/03/12] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Win32 for i386
Compiling strarray.pp
Fatal: Compilation aborted
An unhandled exception occurred at $00402142 :
EAccessViolation : Access violation

Declaring a string as having #$FFFF in it, to me looks as if it is supposed to be a WideString, and #$FFFF being a WideChar?

Declaring the array as array[0..0] of WideString resolves the issue.

Fpc should however not crash on compiling if it is declared as array[0..0] of string.

Jonas Maebe

2010-05-08 13:02

manager   ~0037359

The compiler now gives an error if you try to declare a short/ansistring typed constant containing wide/unicode strings.

The reason is that the compiler cannot convert a wide/unicode string into an ansi/shortstring at compile-time, since it does not know what the ansi encoding will be when the program is executed (and this ansi encoding can even be different every time it is executed).

Kylix does compile the example program, but it converts the #$ffff into #$ff#$20, which I think makes no sense and is a bug in Kylix.

Issue History

Date Modified Username Field Change
2010-04-07 07:44 Thierry Coq New Issue
2010-04-07 07:44 Thierry Coq File Added:
2010-04-07 11:58 Bart Broersma Note Added: 0036514
2010-05-08 13:02 Jonas Maebe Fixed in Revision => 15240
2010-05-08 13:02 Jonas Maebe Status new => resolved
2010-05-08 13:02 Jonas Maebe Fixed in Version => 2.5.1
2010-05-08 13:02 Jonas Maebe Resolution open => fixed
2010-05-08 13:02 Jonas Maebe Assigned To => Jonas Maebe
2010-05-08 13:02 Jonas Maebe Note Added: 0037359
2010-11-16 16:57 Jonas Maebe Status resolved => closed
2010-12-02 23:58 Jonas Maebe Relationship added has duplicate 0018140