Re: backslash-issues



On 2005-06-30, Arjen Markus <arjen.markus@xxxxxxxxxx> wrote:
>
>> there was another thread about this issue, this seems quite nice to me:
>>
>> CHARACTER(LEN=1), PARAMETER :: backslash='\\'
>
> The problem with that approach is that the backslash may not be a
> valid character for the compiler (it is not part of the language's
> character set).

True, and it has even more problems... it doesn't work at all under F.
If i try to compile the following with my F-compiler:

character(len=1), parameter :: backslash = "\\"

I get:

Error: test_backslash.f95, line 13: Character parameter BACKSLASH must
have declared length *

So i change it to:

character(len=*), parameter :: backslash = "\\"

but then the whole 'trick' does not work anymore of course...

And what Arjen said is right, the backslash character does not always
belong to the character set of the processor/compiler... for example
when I compile using my ifc compiler i get:

character(len=1), parameter :: backslash = '\\'
^
Warning 18 at (13:test_backslash.f95) : \ used as an escape character is an extension to standard Fortran 95

This leads me to the conclusion that if you also want to be F-compliant, then
this is the best solution so far (until maybe someone comes up with a better
one :-)

character(len=*), parameter :: backslash = char(92)

With the only remark that you have to hope that your Fortran compiler uses the
ASCII collating sequence for it's character numbering.

Regards,
Bart

--
"Share what you know. Learn what you don't."
.



Relevant Pages

  • Re: New Line Constant Error!
    ... > make a special character that you can't type into your program. ... > tries to combine the backslash with the following character to create ... which the compiler reads as a special sequence that folds down into ... because the sequence backslash-en is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: New Line Constant Error!
    ... it is an "escape" that combines with the character after it to ... So, any time you type a string and put a backslash \ in it, the ... which the compiler reads as a special sequence that folds down into ... special-character processing on this one. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Q: loading Crystal report 10 from file
    ... A backslash in C# string tells the compiler to interpret the following ... string resolves to a single backslash (i.e.: "Treat the next character ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A note on computing thugs and coding bums
    ... It would handle international characters if the execution character ... method I used in "Build Your Own .Net Language and Compiler". ... work areas and counting on Nul is an illusion. ...
    (comp.programming)
  • Re: PL/I string representations
    ... >> of the language, so it was interesting to me, hopefully it will be to ... I found a workable compiler for Fortran in 1971 (with a bug ... >> The specified length is the minimum, and each time a character ... >> string is assigned to E, the length is stored with it. ...
    (comp.programming)