HP aC++ Release Notes Version A.03.85
HP aC++ Release Notes
New Features in Version A.03.25
Chapter 1 55
By default, string literal data now resides in read-only memory rather than read-write memory. This new
default may result in improved run-time performance, because read-only memory is shared. The +ESlit
command line option can be used to explicitly specify this behavior. +ESnolit reverts to storing string
literal data in read-write memory.
NOTE This new default option may cause programs to abort with signal 10 at run-time.
String literals (quoted character strings) are typed as “const char[]” and programs that attempt to
modify string literal data are violating the semantics of this const type. Modifying string literal data at the
source level translates to writing data into read-only memory at runtime and will result in the process
receiving a signal 10 (bus error). Below is an example of such a program:
void f(char *s) { // Warning 829: const char* -> char*
s[0] = ‘S’; // abort: write into read-only memory
}
int main() {
f(“string literal”);
return 0;
}
Programs that attempt to write into a string literal’s read-only memory will trigger warnings and errors at
compile-time. Fixing the program’s compile-time errors and warnings has the benefit of enabling the use of
+ESlit, thus taking advantage of improved run-time efficiency and improving the application’s portability.
The following code generates the compile-time errors shown below:
int main() {
const char *p = “quoted string”;
char* c=p; // Error 440
void main2() {
const char *p = “quoted string”;
char* c;
c=p; // Error 203
aCC -c foo.C
Error 440: “foo.C”, line 3 # Cannot initialize ‘char *’ with
‘const char *’. char* c=p;
^
Error 203: “foo.C”, line 8 # Cannot assign ‘char *’ with ‘
const char *’. c=p;
^
If you see a compile-time warning like the following: