Pragma equivalent
#pragma options [no]macpstr
Purpose
Converts Pascal string literals (prefixed
by the \p escape sequence) into null-terminated strings
in which the first byte contains the length of the string.
For example, when the
-qmacpstr option is in effect,
the compiler converts:
“\pABC”
to:
'\03' , 'A' , 'B' , 'C' , '\0'
Syntax
.-nomacpstr-.
>>- -q--+-macpstr---+------------------------------------------><
Usage
A Pascal string literal always contains the characters "\p.
The characters \p in the middle of a string do not form a Pascal
string literal; the characters must be immediately preceded by the " (double quote) character.
Entering the characters:
'\p' , 'A' , 'B' , 'C' , '\0'
into
a character array does not form a Pascal string literal.
The compiler ignores the -qmacpstr option when the -qmbcs or -qdbcs option is active
because Pascal-string-literal processing is only valid for one-byte characters.
The #pragma options keyword macpstr is only valid at the top of a source file before any C or C++ source statements. If you attempt to use it in the middle of a
source file, it is ignored and the compiler issues an error message.
The following describes how Pascal string literals are processed.
- Because there is no Pascal-string-literal processing of wide strings,
using the escape sequence \p in a wide string literal with the -qmacpstr option, generates a warning message and the escape
sequence is ignored.
- Concatenating a Pascal string literal to a normal string gives a non-Pascal
string. For example, concatenating the strings:
“ABC” “\pDEF”
gives:
“ABCpDEF”
- Concatenating two Pascal string literals, for example, strcat,
does not result in a Pascal string literal. However, as described above, two
adjacent Pascal string literals can be concatenated to form one Pascal string
literal in which the first byte is the length of the new string literal. For
example, concatenating the strings:
“\p ABC” “\p DEF”
or
“\p ABC” “DEF”
results in:
“\06ABCDEF”
- A Pascal string literal cannot be concatenated with a wide string literal.
- The compiler truncates a Pascal string literal that is longer than 255
bytes (excluding the length byte and the terminating NULL) to 255 characters.
- The Pascal string literal is not a basic type
different from other C or C++ string literals. After
the processing of the Pascal string literal is complete, the resulting string
is treated the same as all other strings. If the program passes a C string
to a function that expects a Pascal string, or vice versa, the behavior is
undefined.
- Modifying any byte of the Pascal string literal after the processing has
been completed does not alter the original length value in the first byte.
For example, in the string “\06ABCDEF”, substituting a
null character for one of the existing characters in the middle of the string
does not change the value of the first byte of the string, which contains
the length of the string.
- No errors or warnings are issued when the bytes of the processed Pascal
string literal are modified.
Examples
To compile mypascal.c and convert string literals into Pascal-style strings,
enter:
xlc mypascal.c -qmacpstr