All Questions
Tagged with volatile optimization
40 questions
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){
...
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 ...
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 = ...
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 ...
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?
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 ...
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 ...
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
...
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 ...
-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 ++; } // ...
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 ...
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++
}
...
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 ...
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 ...
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-...