Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
84 views

Does assigning a volatile variable to itself suppress compiler optimization in a loop?

I'm working on a delay loop in C and come across an odd case with volatile. Consider this code: void delay(unsigned int count){ volatile unsigned int timer = count; while (timer > 0){ ...
Alphin Thomas's user avatar
1 vote
0 answers
100 views

Is it possible to tell the compiler that an object reachable through a pointer has changed? [duplicate]

Is there a way to tell the C++ compiler that an object that's reachable through a pointer has changed, even if it has every reason to believe it hasn't? My use-case is something like this: // Three ...
Omnifarious's user avatar
  • 56.2k
0 votes
0 answers
31 views

(void) volatile variable optimization [duplicate]

I am embedded fw engineer. Sometimes we need to make dummy reads of some registers from different serial interfaces. I can do it in several ways: using dummy variable: ... volatile uint8_t dummy = ...
Robert Khan's user avatar
0 votes
0 answers
64 views

Will the read/write of the 8 byte struct in these methods be atomic?

I've been learning about atomic operations and C# alignment + atomicity guarantees. I want to see if I understand them correctly. Will the extension methods in the example be atomic, or is there ...
Petrusion's user avatar
  • 1,201
1 vote
2 answers
273 views

Comparing volatile variable to itself

Can compiler optimize comparing volatile variable to itself and assume it will be equal? Or it has to read twice this variable and compare the two values it got?
arye's user avatar
  • 500
1 vote
1 answer
110 views

gcc optimization ignores program line

Programming the Attiny1634, I try to reuse ram space. Doing so I reused my_array[0] first element to send a u8 value to my_function requiring a pointer to uint8_t, but whatever I did, the function got ...
Panos Kontogiannis's user avatar
3 votes
5 answers
184 views

Optimization allowed on volatile objects

From ISO/IEC 9899:201x section 5.1.2.3 Program execution paragraph 4: In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not ...
izac89's user avatar
  • 3,940
1 vote
1 answer
199 views

Can this volatile access be optimized out?

From ISO/IEC 9899:201x section 5.1.2.3 Program execution: 2 Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side ...
izac89's user avatar
  • 3,940
1 vote
0 answers
71 views

Checking matrix values in nested loops

I'm trying to validate matrix values in nested loop for unit tests. The tests pass on macOS (clang) but fail Ubuntu 18.04 (gcc version 7.3.0). Here what I'm trying to do (I'm trying to validate the ...
recp's user avatar
  • 393
-1 votes
2 answers
812 views

How to instruct avr-gcc to optimize volatile variables?

Code for an interrupt service handler: volatile unsigned char x = 0; void interruptHandler() __attribute__ ((signal)); void interruptHandler() { f(); g(); } Calls: void f() { x ++; } // ...
feklee's user avatar
  • 7,725
5 votes
4 answers
2k views

Does the -O0 compiler flag have the same effect as the volatile keyword in C?

When you use the -O0 compiler flag in C, you tell the compiler to avoid any kind of optimization. When you define a variable as volatile, you tell the compiler to avoid optimizing that variable. Can ...
Arash Fotouhi's user avatar
1 vote
1 answer
600 views

volatile keyword does not work for gcc inline assembly

I need to run this simple inline assembly code: #include <stdio.h> int count; int main() { count = 0; for (int i = 0; i < 10; i++) { asm volatile ("incl count"); // count++ } ...
Behrooz Ns's user avatar
1 vote
1 answer
146 views

Optimizing volatile variables

My understanding is that the C++ standard mandates that accesses to volatile objects are evaluated strictly according to the rules of the abstract machine. I am sure that means that the number of ...
John Yates's user avatar
  • 1,057
2 votes
1 answer
199 views

Changes to volatile variable only occur when stepping through code or optimisation turned off

I am programing a TI TM4C microcontroller and stuck with some unusual behavior where the controller is not working as I expect it. I expect the volatile keyword to work such that any reads or writes ...
Hugoagogo's user avatar
  • 1,646
2 votes
0 answers
65 views

In gcc is there a way to find out which symbols are being touched by the optimizer?

Very diffuse question I admit - maybe you can just give me a hint in the right direction.. In a fairly large embedded C based project we observe different behavior when updating from arm-none-eabi-...
frans's user avatar
  • 9,878

15 30 50 per page