Perhaps in good ol' K&R C, but not in ANSI C:

 char s1[]="Hello";
 char s2[]="goodbye";
 char* s3 = "jones";
 char * const s4="lexus";
 const char * s5 = "trout";
 s3=s1;
 s3=s2;
 s1=s2;
 s1=s3;
 s4=s1;
 s4=s3;
 s5=s1;
 s5=s3;
 s1 = "blue winged olive";
 s5 = "light cahill";

Error   : not an lvalue
HelloWorld.c line 539    s1=s2;

Error   : not an lvalue
HelloWorld.c line 540    s1=s3;

Error   : illegal assignment to constant
HelloWorld.c line 541    s4=s1;

Error   : illegal assignment to constant
HelloWorld.c line 542    s4=s3;

Error   : not an lvalue
HelloWorld.c line 545    s1 = "blue winged olive";


(compiled with CW)


-----Original Message-----
From: Hal DeVore <[EMAIL PROTECTED]>
To: Butch Howard <[EMAIL PROTECTED]>
Date: Wednesday, March 10, 1999 6:34 PM
Subject: Re: Variable storage question


>[EMAIL PROTECTED] wrote:
>> char s1[] = "Hello";
>>
>> the pointer s1 itself probably takes up no space anywhere accesses to the
>> data are likely to be coded relative to the stack pointer or a register.
>> this is because the pointer is constant (the data is not, however).
>> Since where the pointer points can never be changed the compiler doesn't
>> need to have a place to record it other than code.
>
>
>I don't think that's right, Butch.  That declaration is neither a const
>pointer nor a pointer to const so either the thing it points to or the
>pointer itself CAN change.  So it's gotta live somewhere.
>
>-Hal <*> Eschew Obfuscation.
>
>

Reply via email to