Character

The character type specifier must include the CHARACTER keyword. See CHARACTER for details on declaring entities of type character.

The form of a character literal constant is:
Read syntax diagramSkip visual syntax diagram
>>-+---------------+--+-'--character_string--'-+---------------><
   '-kind_param--_-'  '-"--character_string--"-'   

kind_param
is either a digit-string or a scalar-int-constant-name

XL Fortran supports a kind type parameter value of 1, representing the ASCII collating sequence.

Character literal constants can be delimited by double quotation marks as well as apostrophes.

character_string consists of any characters capable of representation in XL Fortran, except the new-line character, because it is interpreted as the end of the source line. The delimiting apostrophes (') or double quotation marks (") are not part of the data represented by the constant. Blanks embedded between these delimiters are significant.

If a string is delimited by apostrophes, you can represent an apostrophe within the string with two consecutive apostrophes (without intervening blanks). If a string is delimited by double quotation marks, you can represent a double quotation mark within the string with two consecutive double quotation marks (without intervening blanks). The two consecutive apostrophes or double quotation marks will be treated as one character.

You can place a double quotation mark within a character literal constant delimited by apostrophes to represent a double quotation mark, and an apostrophe character within a character constant delimited by double quotation marks to represent a single apostrophe.

The length of a character literal constant is the number of characters between the delimiters, except that each pair of consecutive apostrophes or double quotation marks counts as one character.

A zero-length character object uses no storage.

In XL Fortran each character object requires 1 byte of storage.

For compatibility with C language usage, XL Fortran recognizes the following escape sequences in character strings:

Escape Meaning
\b Backspace
\f Form feed
\n New-line
\r New-line
\t Tab
\0 Null
\'

Apostrophe
(does not terminate a string)

\"

Double quotation mark
(does not terminate a string)

\\ Backslash
\x x, where x is any other character

To ensure that scalar character constant expressions in procedure references are terminated with null characters (\0) for C compatibility, use the -qnullterm compiler option. (See -qnullterm in the XL Fortran Compiler Reference for details and exceptions).

All escape sequences represent a single character.

If you do not want these escape sequences treated as a single character, specify the -qnoescape compiler option. (See -qescape in the XL Fortran Compiler Reference.) The backslash will have no special significance.

The maximum length of a character literal constant depends on the maximum number of characters allowed in a statement.

If you specify the -qctyplss compiler option, character constant expressions are treated as if they are Hollerith constants. See Hollerith constants for information on Hollerith constants. For information on the -qctyplss compiler option, see -qctyplss option in the XL Fortran Compiler Reference

XL Fortran supports multibyte characters within character literal constants, Hollerith constants, H edit descriptors, character-string edit descriptors, and comments through the -qmbcs compiler option.

Support is also provided for Unicode characters and filenames. If the environment variable LANG is set to UNIVERSAL and the -qmbcs compiler option is specified, the compiler can read and write Unicode characters and filenames. See the XL Fortran Compiler Reference for more information.