This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: volatile semantics


> From: Paul Schlie <schlie@comcast.net>
>> From: Gabriel Dos Reis <gdr@integrable-solutions.net>
>> I don't understand what you mean here.  Are you seriously suggesting
>> that 
>> 
>>      int main(void) {
>>         const int x = 4;
>>         *(int*)&x = 3;
>>      }
>> 
>> is well-defined?
> 
> Actually yes, I believe it's well defined that:
> 
> - The assignment reference to x is valid as it's not specified as const,
>   therefore must be performed, unless:
> 
> - It is KNOWN at the time of compilation that an absents of it's side effect
>   would have no logical consequential effect (as might be the case for
>   example if a write to a ROM allocated object were silently physically
>   ignored, but not for example if a write were specified to a RAM allocated
>   object), however:
> 
> - As allocation side effects may differ for different targets and/or
>   implementations, the behavioral consequence of the correctly specified and
>   valid assignment to a const declared object may also correspondingly
>   differ; so therefore although valid, the effect of the assignment is not
>   itself warranted to be portable (but that it will logically occur is).

- Just as if given:

     void foo(void) {
       int *x = 4;
       *x = 3;
       (const int *)x = 5;
     }

  The assignment to *x = 3 must logically occur (although it's not warranted
  what the behavioral effect of the assignment may actually be for a given
  target/implementation, as there's no requirement that RAM or anything in
  particular is mapped to address 4. (Unless an implementation KNOWS it's
  side effect is inconsequential to the execution of the specified program.)

  Correspondingly, (const int *)x = 5 must not logically occur, as an
  assignment to a const qualified object is invalid.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]