For Programmers: Free Programming Magazines  


Home > Archive > Fortran > November 2007 > Re: Backslashes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Backslashes
Steven G. Kargl

2007-11-26, 7:17 pm

In article <xKF2j.53300$if6.39182@bgtnsc05-news.ops.worldnet.att.net>,
Dick Hendrickson <dick.hendrickson@att.net> writes:
> Steven G. Kargl wrote:
>
> As I said before, it's the PROCESSOR character set, not the Fortran
> character set, that's the interesting thing for character constants.
>
> 3.1 is clear that the processor character set includes the
> [possibly empty] set of "other characters" and the Fortran
> character set.
>
> 3.1.5 is clear that additional characters may be representable
> and, if they are, they can appear in character constants.
>
> 4.3.2.1 says the length of a character string is the number of
> characters in it.
>
> So, what does gfortran do with "\\"? I think most compilers that
> treat a \ as an escape treat "\\" as if it were "\". But, isn't that
> non-conforming?


How so?

> If you can have a \ in a string (no matter how you
> represent it) doesn't it have to be a representable character?


AFAICT, the F95 standard doesn't address how one expresses
the representable backslash character in a text file. Section
14.6.3.1 declares that a "nonpointer scalar object of type
default character and character length one occupies a one
character storage unit". The standard does not address how
one puts a new line or back space or other character into a
a single storage unit. One might even argue that Sec. 1.4(1)
allows the transformation of "\\" into \ or "\n" into the
character represented by ACHAR(10), etc.

> and then doesn't the length of "\\" have to be 2?


program a
character(len=10) s1, s2
s1 = '\'
s2 = s1
print '(2I2)', len_trim(s1), len_trim(s2)
end program

troutmask:kargl[210] gfc -o z a.f90
troutmask:kargl[211] ./z
1 1
troutmask:kargl[216] gfc -o z -fno-backslash a.f90
troutmask:kargl[217] ./z
2 2

program a
character(len=10) s1, s2
s1 = '\'
write(s2,'(A)') s1
print '(2I2)', len_trim(s1), len_trim(s2)
if (s1 /= s2) then
print *, 'Oh, no!'
end if
end program

troutmask:kargl[225] gfc -o z a.f90
troutmask:kargl[226] ./z
1 1
troutmask:kargl[227] gfc -o z -fno-backslash a.f90
troutmask:kargl[228] ./z
2 2


It's unfortunate that people refuse to read the documentation
provided. There is an option to turnoff this behavior. But,
I've grown tired of the whining about gfortran's behavior.
Now, I can watch the others complain about gfortran's gratuitous
differences with g77 compatibility.

Index: ChangeLog
========================================
===========================
--- ChangeLog (revision 130443)
+++ ChangeLog (working copy)
@@ -1,3 +1,8 @@
+2007-11-26 Steven G. Kargl <kargls@comcast.net>
+
+ * options.c: Change default behavior of backslash processing.
+ * invoke.texi: Update documentation.
+
2007-11-25 Jerry DeLisle <jvdelisle@gcc.gnu.org>

PR fortran/33152
Index: invoke.texi
========================================
===========================
--- invoke.texi (revision 130443)
+++ invoke.texi (working copy)
@@ -121,7 +121,7 @@ by type. Explanations are in the follow
-ffixed-line-length-@var{n} -ffixed-line-length-none @gol
-ffree-line-length-@var{n} -ffree-line-length-none @gol
-fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 @gol
--fcray-pointer -fopenmp -fno-range-check -fno-backslash -fmodule-private}
+-fcray-pointer -fopenmp -fno-range-check -fbackslash -fmodule-private}

@item Error and Warning Options
@xref{Error and Warning Options,,Options to request or suppress errors
@@ -233,12 +233,12 @@ Do nothing if this is already the defaul
@cindex character set
Allow @samp{$} as a valid character in a symbol name.

-@item -fno-backslash
-@opindex @code{fno-backslash}
+@item -fbackslash
+@opindex @code{backslash}
@cindex backslash
@cindex escape characters
-Change the interpretation of backslashes in string literals from
-``C-style'' escape characters to a single backslash character.
+Change the interpretation of backslashes in string literals
+from a single backslash character to ``C-style'' escape characters.

@item -fmodule-private
@opindex @code{fmodule-private}
Index: options.c
========================================
===========================
--- options.c (revision 130443)
+++ options.c (working copy)
@@ -95,7 +95,7 @@ gfc_init_options (unsigned int argc ATTR
gfc_option.flag_repack_arrays = 0;
gfc_option.flag_preprocessed = 0;
gfc_option.flag_automatic = 1;
- gfc_option.flag_backslash = 1;
+ gfc_option.flag_backslash = 0;
gfc_option.flag_module_private = 0;
gfc_option.flag_backtrace = 0;
gfc_option.flag_allow_leading_underscore = 0;


--
Steve
http://troutmask.apl.washington.edu/~kargl/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com