Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* Might this be a VMS or C problem on the AXP?
@ 1993-03-27 20:47 J. Daniel Smith
  1993-03-27 22:16 ` Marcus J Ranum
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: J. Daniel Smith @ 1993-03-27 20:47 UTC (permalink / raw)


The follwoing short program produces "correct" resusts on the
DECstation, VAX/VMS, and HP boxes, but fails with a SEGV on the AXP/VMS
when an attempt is made to change the value of the string literal.

-----
#include <stdio.h>

int main(void)
{
    char *c = "x";
    
    c[0] = 'x'; c[1] = '\0';
    
    printf("c = \"%s\"\n", c);
    
    c[0] = 'y';
    printf("c = \"%s\"\n", c);
}
-----

According to the ANSI spec, 
   "If a program attempts to modify a string literal..., the behavior
   is undefined". (Section 3.1.4)
so, strickly speaking, I guess this can't be considered a bug.  Still,
it is a bit surprising to me that it does get detected and cause a
failure on the AXP/VMS, especially since it does not crash under
VAX/VMS.

Can someone explain excatly what is happening on the AXP/VMS?  Is
there a way to make this program crash under VAX/VMS (or other
platforms)?

Thanks,
   Dan
-- 
==== message is author's opinion only -- it is not an official statement ====
J. Daniel Smith                              dsmith@ann-arbor.applicon.slb.com
Applicon, Inc.                               dsmith@aaaca1.sinet.slb.com 
Ann Arbor, Michigan (USA)                    AAACA1::DSMITH (SINet)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Might this be a VMS or C problem on the AXP?
  1993-03-27 20:47 Might this be a VMS or C problem on the AXP? J. Daniel Smith
@ 1993-03-27 22:16 ` Marcus J Ranum
  1993-03-27 22:17 ` Ron Natalie
  1993-03-29  2:43 ` Blair Phillips - Digital
  2 siblings, 0 replies; 5+ messages in thread
From: Marcus J Ranum @ 1993-03-27 22:16 UTC (permalink / raw)


>According to the ANSI spec, 
>   "If a program attempts to modify a string literal..., the behavior
>   is undefined". (Section 3.1.4)

	Undefined means that it can do anything it likes, including
"work" more or less correctly. The code is broken, but you cannot
expect the system to always trap it.

	[My usual diatribe about C's failings, and why C code for any
non-trivial applications should be developed under interpreted environments
like Saber-C omitted.]

mjr.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Might this be a VMS or C problem on the AXP?
  1993-03-27 20:47 Might this be a VMS or C problem on the AXP? J. Daniel Smith
  1993-03-27 22:16 ` Marcus J Ranum
@ 1993-03-27 22:17 ` Ron Natalie
  1993-03-29  2:43 ` Blair Phillips - Digital
  2 siblings, 0 replies; 5+ messages in thread
From: Ron Natalie @ 1993-03-27 22:17 UTC (permalink / raw)


A compiler is free to put these in shareable (i.e. read only) storage.
This is probably what is happening.  Oddly, on OSF/1 it works as you
would expect.

-Ron


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Might this be a VMS or C problem on the AXP?
  1993-03-27 20:47 Might this be a VMS or C problem on the AXP? J. Daniel Smith
  1993-03-27 22:16 ` Marcus J Ranum
  1993-03-27 22:17 ` Ron Natalie
@ 1993-03-29  2:43 ` Blair Phillips - Digital
  1993-04-02 13:45   ` J. Daniel Smith
  2 siblings, 1 reply; 5+ messages in thread
From: Blair Phillips - Digital @ 1993-03-29  2:43 UTC (permalink / raw)



In article <dsmith.733265264@aa.cad.slb.com>, dsmith@ann-arbor.applicon.slb.com (J. Daniel Smith) writes:
>According to the ANSI spec, 
>   "If a program attempts to modify a string literal..., the behavior
>   is undefined". (Section 3.1.4)
>so, strickly speaking, I guess this can't be considered a bug.  Still,
>it is a bit surprising to me that it does get detected and cause a
>failure on the AXP/VMS, especially since it does not crash under
>VAX/VMS.
>
>Can someone explain excatly what is happening on the AXP/VMS?  Is
>there a way to make this program crash under VAX/VMS (or other
>platforms)?

Can't help you make it crash on other platforms, but there is a switch to make
it work on AXP/VMS:

$ CC/ASSUME=[NO]WRITEABLE_STRING_LITERALS

By default, string literals are defined in a readonly PSECT by DEC C.
The /ASSUME=WRITEABLE_STRING_LITERALS switch (aka "Aid to brain-dead programs")
puts them in a read-write PSECT.

----------
Blair Phillips					Blair.Phillips@cao.mts.dec.com
Digital Equipment Corp (Aust) P/L		Phone: (+61 6) 2754874
Canberra, Australia				FAX  : (+61 6) 2473654
X.400: "C=AU; A=OTC; P=Digital; O=Digital; OU=SNO; S=Phillips; G=Blair"
{Any opinions expressed are my own, not those of Digital Equipment Corporation}



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Might this be a VMS or C problem on the AXP?
  1993-03-29  2:43 ` Blair Phillips - Digital
@ 1993-04-02 13:45   ` J. Daniel Smith
  0 siblings, 0 replies; 5+ messages in thread
From: J. Daniel Smith @ 1993-04-02 13:45 UTC (permalink / raw)


In <1993Mar29.024307.3711@dbased.nuo.dec.com> blair@snogum.cao.dec.com (Blair Phillips - Digital) writes:
>In article <dsmith.733265264@aa.cad.slb.com>, dsmith@ann-arbor.applicon.slb.com (J. Daniel Smith) writes:
>>According to the ANSI spec, 
>>   "If a program attempts to modify a string literal..., the behavior
>>   is undefined". (Section 3.1.4)
>>so, strickly speaking, I guess this can't be considered a bug.  Still,
>>it is a bit surprising to me that it does get detected and cause a
>>failure on the AXP/VMS, especially since it does not crash under
>>VAX/VMS.
>>
>>Can someone explain excatly what is happening on the AXP/VMS?  Is
>>there a way to make this program crash under VAX/VMS (or other
>>platforms)?

>[...]
>$ CC/ASSUME=[NO]WRITEABLE_STRING_LITERALS
>
>By default, string literals are defined in a readonly PSECT by DEC C.
>The /ASSUME=WRITEABLE_STRING_LITERALS switch (aka "Aid to brain-dead programs")
>puts them in a read-write PSECT.
Of course I changed the code so it was no longer a "brain-dead
program".  Thanks to all those who explained about the writable PSECT
under VMS.  

   Dan
-- 
==== message is author's opinion only -- it is not an official statement ====
J. Daniel Smith                              dsmith@ann-arbor.applicon.slb.com
Applicon, Inc.                               dsmith@aaaca1.sinet.slb.com 
Ann Arbor, Michigan (USA)                    AAACA1::DSMITH (SINet)


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1993-04-02 13:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-03-27 20:47 Might this be a VMS or C problem on the AXP? J. Daniel Smith
1993-03-27 22:16 ` Marcus J Ranum
1993-03-27 22:17 ` Ron Natalie
1993-03-29  2:43 ` Blair Phillips - Digital
1993-04-02 13:45   ` J. Daniel Smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox