[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference vmszoo::vms_posix

Title:POSIX for OpenVMS - Public forum
Notice:Internal users of V2.0 please register in note 909
Moderator:STAR::PARKE
Created:Fri Jan 04 1991
Last Modified:Mon Jun 02 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1370
Total number of notes:5127

1364.0. "Segmentation fault not in UNIX" by SPANIX::JULIANR (ALPHAbet = Our bet on ALPHA) Tue Mar 25 1997 06:09

The following piece of code produces a segmentation violation error 
whenever it is executed on OpenVMS 6.2 and OpenVMS POSIX 2.0:

#include <stdio.h>


void demo (char *);

main ()
{
	demo ("Hello");
}

demo (char *s)
{
	*s = 'p';
}

This code doesn't produce any error on any UNIX, including ours.

What is wrong ? Will OpenVMS POSIX 3.0 help ?

Regards,

Julian Rodriguez
Digital Spain, UNIX Ambassador
 
T.RTitleUserPersonal
Name
DateLines
1364.1SPECXN::DERAMODan D&#039;EramoTue Mar 25 1997 08:4712
        You can't modify a string literal, which is what the demo()
        function is trying to do to the first character of the "Hello"
        string literal.  By default DEC C places string literals in
        read-only storage.  DEC C has a compiler command line
        qualifier /ASSUME=WRITABLE_STRING_LITERALS to override the
        default.  I'm not sure off hand what that look like in POSIX
        but "man c89" should show you.
        
        Under the ANSI C standard attempting to modify a string
        literal leads to undefined behavior.
        
        Dan
1364.2c89 -Wc,ASSUME=WRITABLE_STRING_LITERALSMUCTEC::BECKERHartmut B., VMS &amp; Languages, MunichWed Mar 26 1997 17:125
    After -Wc, you can pass any DCL-style qualifier with value(s) to the
    compiler.
    
    Hth,
    Hartmut