[fpc-devel] Some thoughts on multi-line string support, and a possible syntax that I think is perfectly clean and Pascal-ish.

Ben Grasset operator97 at gmail.com
Sat Jul 6 02:30:20 CEST 2019


On Fri, Jul 5, 2019 at 8:14 PM Ben Grasset <operator97 at gmail.com> wrote:

> On Fri, Jul 5, 2019 at 8:08 PM Ryan Joseph <genericptr at gmail.com> wrote:
>
>> ah! Your code works but mine doesn’t! maybe the line ending are messing
>> it up? I get "String constant too long while ansistrings are disabled”.\
>>
>
> No, that makes no sense whatsoever.
>
> Another example:
>
> {$mode objfpc}
> { explicitly set H- ! }
> {$H-}
> { using CRLF while my file is actually LF, just for fun }
> {$MULTILINESTRINGLINEENDING CRLF}
>
> program test;
>
> var lines: ansistring = `
>   #version 150
>
>   uniform sampler2D textures[8];
>   in vec2 vertexTexCoord;
>   in vec4 vertexColor;
>   in float vertexUVMap;
>   out vec4 fragColor;
>
>   void main()
>   {
>     if (vertexUVMap == 255) {
>       fragColor = vertexColor;
>     } else {
>       fragColor = texture(textures[int(vertexUVMap)], vertexTexCoord.st);
>       if (vertexColor.a < fragColor.a) {
>         fragColor.a = vertexColor.a;
>       }
>     }
>   }`;
>
> begin
>   WriteLn(lines);
> end.
>
> I'm not even sure which code (that is actually a complete program with a
> begin and end) you're talking about.
>

I just noticed, in fact: the compiler actually completely ignores {$H+} and
{$H-} for "typed" string constants *and* variables, in all cases. Even with
{$H-}, and with not "ansistring", but "string", my above example still
works (i.e. the compiler implicitly "uptypes" it to an ansistring if it
needs to, basically). Only for "true constant" strings does it care about
{$H+} and {$H-} at all.

I'm unsure whether or not this is intentional behaviour.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190705/ceda63f5/attachment.html>


More information about the fpc-devel mailing list