On 23 Mar 2002 at 5:12, Frank Heckenbach wrote:
[...]
Perhaps in EP mode, it should generate an error. In other modes, it should [a] at least generate a warning,
Warnings only exist at compile-time. That's more difficult (the compiler would have to analyze the minimum length of the concatenation) that at runtime. Ideally, it should do both ...
Well, at least it can generate an error. But see below ...
or, [b] (and perhaps more controversially), treat string literals of < 255 chars as strings of 255 capacity.
No, why? For BP compatibility, it should be enough to treat `String' as `String[255]'
It isn't enough. Try this program;
program testfoo; procedure foo (s : string); begin writeln (sizeof (s)); end; procedure bar (const s: string); begin writeln (sizeof (s)); end; begin foo ('Frank'); bar ('Chief'); end.
In GPC, it prints '16', '16'. In BP, it prints '256', '256'. Similarly with TMT Pascal. With compilers that have AnsiStrings (Delphi, Virtual Pascal) it prints '256', '256', unless you compile with {$H+} (i.e., in "AnsiString" or "Long String" mode), in which case it prints '4', '4' (AnsiStrings are internally pointers).
So you can see that GPC, on this issue, is entirely in a class of its own (i.e., not compatible with any other Pascal compiler in any respect - and certainly not with BP).
(which GPC currently does only in contexts where an undiscriminated `String' normally makes no sense, but I think we >already discussed a switch) ...
We did. Maybe it's time to consider implementing it? Perhaps we could accept "{$H-}" and something like "--short-strings" or "--BP-strings" to treat undiscriminated strings - function results, variables, record/object fields, and string literals, as BP strings, and without any warnings too. The default could be "{$H+}" or "--long-strings", which, at present would simply mean exactly what we have now (i.e., warnings, etc.) - or we (more controversially) could even treat undiscriminated strings in {$H+} mode as errors and refuse them at compile time. I am not all sure that all or any of this is a good idea. I just want to generate some discussion on the issue.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~African_Chief email: African_Chief@bigfoot.com