Hello,
I noticed that declaration of variable like:
a:string[1]; is not valid any more in fpc-2.0.2, so how can I declare a variable to get few char string instead of full length
thanks
Andy

Mailing lists / fpc-pascal / 2006-02
11 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hello,
I noticed that declaration of variable like:
a:string[1]; is not valid any more in fpc-2.0.2, so how can I declare a variable to get few char string instead of full length
thanks
Andy
Andrzej Baran wroteI noticed that declaration of variable like: a:string[1]; is not valid any more in fpc-2.0.2, so how can I declare a variable to get few char string instead of full length
It works here, even if ansistrings are the default ({$h+} or Delphi mode activated). The only thing that (logically) doesn't work here is "a:ansistring[1]".
Note that 2.02 has a bug whereby reading such length-limited strings can cause a buffer overflow (which has been fixed in the mean time).
Jonas
This also doesn't work (I don't see why not?)
{$mode delphi}
var x : shortstring[4];
begin
end.[Snail] </home/marcov/testing> fpc testshort
Free Pascal Compiler version 2.1.1 [2006/02/10] for i386 Copyright (c) 1993-2005 by Florian Klaempfl
Target OS: FreeBSD/ELF for i386
Compiling testshort.pp
testshort.pp(5,23) Error: Error in type definition testshort.pp(8,4) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
Error: /home/marcov/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
[Snail] </home/marcov/testing>
Because shortstring is defined as String[255]
Michael.
Hmm. How do I get real shortstring behaviour in delphi mode then?
Marco van de Voort wrote> Because shortstring is defined as String[255] Hmm. How do I get real shortstring behaviour in delphi mode then?
A string[255] is identical to a "real shortstring".
Jonas
I mean including the possibilties to have non-255 sizes.
Marco van de Voort wroteI mean including the possibilties to have non-255 sizes.
var x : string[4];I suppose?
Apparantly so yes. Assumed that would equal to ansistring[4], but it does to tp string[4].
I mean including the possibilties to have non-255 sizes.
Simple:
Var
A : String[10];
{$H+} just means that for
A : String;A is an ansistring.
{$H-} means that for
A : String;A is a 255 char string, TP style, and hence is equivalent to
A : ShortString
As soon as there is a size indication, it's a TP-style string.
Michael.
Apparantly so yes. Assumed that would equal to ansistring[4], but it does to tp string[4].
TP is correct. Ansistring[4] is not valid, never...
Michael.