FORTRAN 77 Language Reference

Character Constants

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.

Example: Character constants:

"abc" 		"abc"
"ain't"		'in vi type "h9Y'

Null Characters @

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'
demo% f77 NulChr.f
demo% a.out

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 ) 
demo% f77 NulVar.f
demo% a.out
a c 

Escape Sequences @

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 





Carriage return 






Form feed 


Vertical tab 




Apostrophe, which does not terminate a string 


Quotation mark, which does not terminate a string 



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.