[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How does string.format handle undefined behavior?
- From: Viacheslav Usov <via.usov@...>
- Date: Tue, 7 Sep 2021 21:45:41 +0200
On Mon, Sep 6, 2021 at 7:18 PM Lorenzo Donati
<lorenzodonatibz@tiscali.it> wrote:
> For example, assuming x and y are 16 bit quantities on an 8 bit MCU,
> if you write:
>
> x = <expr1>;
> y = <expr2>;
>
> there is no way in C99 to ensure that the updating of x happens
> completely before the updating of y (the upper 8 bits and the lower 8
> bits of each can be modified in any order-usually for optimization
> purposes).
Unless you are talking about setting x and y from two different
threads, and unless you also need to be wary of
interrupts/signals/etc, it is enough to have x and y marked as
volatile in C99.
In later versions, atomics might be a better choice.
Cheers,
V.