A 'trick' that has helped in the past to put code into a 'cage' is doing just 
that: put it into a cage.

do {...}while(0);

The compiler shouldn't optimize across the code block barrier.
I'm not sure what the C standard says about this, but in the past, this 
perfectly worked.
I use this as default for critical section in my atomic macro:

#define ATOMIC(x) do{ intcount++; __disable_interrupts(); do{x}while(0); if 
(!(--intcount))__enable_interrupts();}while(0)
(reconstructed from memory)

The only disadvantage I encuntered so far is that the round macro parameter 
brackets are not identified as code block delimites by the 
editor.

JMGross

----- Ursprüngliche Nachricht -----
Von: David Brown
An: Peter Bigot
Gesendet am: 08 Jan 2012 02:08:50
Betreff: Re: [Mspgcc-users] Simulation and algorithm timing

Not only /may/ actions (calculations, non-volatile read/write accesses, 
etc.) be moved across volatile accesses, but it has been seen to happen 
in practice, causing some confusion to posters on lists like this and 
the equivalent avr-gcc mailing lists.

In particular, people seem to get quite upset when the compiler moves 
code back and forth across interrupt disable/restore pairs!


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to