A character-string constant is a string of characters enclosed in apostrophes or quotes. The apostrophes are standard; the quotes are not. @
If you compile with the -xl option, then the quotes mean something else, and you must use apostrophes to enclose a string.
To include an apostrophe in an apostrophe-delimited string, repeat it. To include a quote in a quote-delimited string, repeat it. Examples:
'abc' "abc" 'ain''t' "in vi type ""h9Y"
If a string begins with one kind of delimiter, the other kind can be embedded within it without using the repeated quote or backslash escapes. See Table 2-3.
"abc" "abc" "ain't" 'in vi type "h9Y'
Each character string constant appearing outside a DATA statement is followed by a null character to ease communication with C routines. You can make character string constants consisting of no characters, but only as arguments being passed to a subprogram. Such zero length character string constants are not FORTRAN standard.
Example: Null character string:
demo% cat NulChr.f write(*,*) 'a', '', 'b' stop end demo% f77 NulChr.f NulChr.f: MAIN: demo% a.out ab demo%
However, if you put such a null character constant into a character variable, the variable will contain a blank, and have a length of at least 1 byte.
Example: Length of null character string:
demo% cat NulVar.f character*1 x / 'a' /, y / '' /, z / 'c' / write(*,*) x, y, z write(*,*) len( y ) end demo% f77 NulVar.f NulVar.f: MAIN: demo% a.out a c 1 demo%
For compatibility with C usage, the following backslash escapes are recognized. If you include the escape sequence in a character string, then you get the indicated character.
Table 2-3 Backslash Escape Sequences
Escape Sequence |
Character |
---|---|
\n |
Newline |
\r |
Carriage return |
\t |
Tab |
\b |
Backspace |
\f |
Form feed |
\v |
Vertical tab |
\0 |
Null |
\' |
Apostrophe, which does not terminate a string |
\" |
Quotation mark, which does not terminate a string |
\\ |
\ |
\x |
x, where x is any other character |
If you compile with the -xl option, then the backslash character (\) is treated as an ordinary character. That is, with the -xl option, you cannot use these escape sequences to get special characters.
Technically, the escape sequences are not nonstandard, but are implementation- defined.