![]() |
![]() HP OpenVMS Systemsask the wizard |
![]() |
The Question is: I have problems finding assignment to readonly memory when we changed to DEC C v5.7 and start using using /STANDARD=RELAXED_ANSI89. With earlier version and /STANDARD=VAXC where the following code allowed and working: main() char *s = "FOO"; strcpy(s, "BAR"); This will cause an access violation with the new compiler and /RELAXED_ANSI89 qualifier. Is there a way in compile time to detect these constructs without having to do it the hard way (or revering to the VAXC switch)? Regards, Anders Wiklund SEB merchant bank in Stockholm The Answer is : There is no way to automatically detect any attempt to write to string constants, save for the run-time capture of the errors resulting from the attempt(s). A signal handler activation or stack dump resulting from the access violation (ACCVIO), in other words... Enabling /WARNING for CHECK, DEFUNCT, or QUESTCODE may be of interest, though these will not flag this particular programming error. The option /ASSUME=[NO]WRITABLE_STRING_LITERALS may also be of interest, as this will permit the application to write to the string "constants". You can also (more selectively) use the equivalent #pragma to enable this. But, as stated, there is no way to automatically and reliably detect (at compile time) an attempt to write to a constant.
|