This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


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

gcc volatile behaviour


>>>>> "Zoltan" == Zoltan Kocsi <zoltan@bendor.com.au> writes:

    Zoltan> I've contated Dennis Ritchie, and he wrote me that in his
    Zoltan> oppinion the wording of the standard (WRT assignment
    Zoltan> operators) is ambiguous.  According to the standard
    Zoltan> committee this ambiguity is deliberate and is not
    Zoltan> ambiguity but freedom.  I'm asking for the excercising of
    Zoltan> this freedom in gcc the other way :-)

Actually, if you are indeed writing a C program, and not a gcc
program, then you need to write your source code in such a manner that 
it always executed with the intended semantics regardless of which
compiler you are using.  By you own admission in an earlier post, the
gcc/egcs team could change the behaviour at any time.  I think a
coding for strcpy that would always give the correct behaviour would
be: 

   void srtcpy(volatile char* src, volatile char* dst) {
     char ch;
     for (ch = '\1';       /* force entry into loop the first time */
          ch != '\0';
          src++, dst++) {
       ch = *src;
       *dst = ch;
     }
   }

Since most modern C compilers do a very good job at optimizing simple
for loops, I expect this coding will generate code as efficient as any 
other coding.  I also think this will not generate any spurious or
surprising fetches from either the source or destination strings.

-- 
--------  "And there came a writing to him from Elijah"  [2Ch 21:12]  --------
R. J. Brown III  rj@elilabs.com http://www.elilabs.com/~rj  voice 847 543-4060
Elijah Laboratories Inc. 457 Signal Lane, Grayslake IL 60030  fax 847 543-4061
-----  M o d e l i n g   t h e   M e t h o d s   o f   t h e   M i n d  ------

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


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