
Re: ANSI C, гарантирано прочитане на адрес от паметта.
SPI->DR;
би трябвало да работи... току що си загубих половин час да ровя в последния стандарт
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf, за да разбера какво би трябвало да е гарантирано в такъв случай, но то C-стандарта не е като едновремещните C стандарти (какви C стандарти имаше едно време...) - сега на човек му трябва юридическо образование, за да го разбере... абе добре е все още - само 700 страници са, от които реално под 200 са за самия език; за сравнение, това, което намерих за C++ - са около 1300 страници, което ме шокира - на мастит език като C++ би трябвало, си мисля, да му е поне 3000 страници стандарта... както е казал поетът - 'я, какъв голям мафиот, а с каква малка пишка'
в случая насилствената смяна на типа с (void) просто няма смисъл - синтактично е правилна, но няма смисъл
@Цецо
SPI->DR;
ще работи, със сигурност - майната му на стандарта, една много проста причина ще дам - виждал съм достатъчно комерсиален код, който ползва точно твоята конструкция, за точно твоята цел (в интерес на истината, почти всичко, което съм виждал, е било с '(void)' отпред, явно е някак си романтично така да се пише); ако производителите на компилатори променят това поведение - жална им майка... да речем, че който плаща - той поръчва музиката
за протокола прилагам някои остроумни извадки от стандарта, докато се рових:
------------------------------------------------------------------
5.1.2.3 Program execution
1 The semantic descriptions in this International Standard describe the behavior of an
abstract machine in which issues of optimization are irrelevant.
...
2 Accessing a volatile object, modifying an object, modifying a file, or calling a function
that does any of those operations are all side effects, 12) which are changes in the state of
the execution environment. Evaluation of an expression in general includes both value
computations and initiation of side effects. Value computation for an lvalue expression
includes determining the identity of the designated object.
...
6 The least requirements on a conforming implementation are:
— Accesses to volatile objects are evaluated strictly according to the rules of the abstract
machine....
...
3 An assignment operator stores a value in the object designated by the left operand. An
assignment expression has the value of the left operand after the assignment, 111) but is not
an lvalue. The type of an assignment expression is the type the left operand would have
after lvalue conversion. The side effect of updating the stored value of the left operand is
sequenced after the value computations of the left and right operands. The evaluations of
the operands are unsequenced.
...
111) The implementation is permitted to read the object to determine the value but is not required to, even
when the object has volatile-qualified type.
...
7 An object that has volatile-qualified type may be modified in ways unknown to the
implementation or have other unknown side effects. Therefore any expression referring
to such an object shall be evaluated strictly according to the rules of the abstract machine,
as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the
object shall agree with that prescribed by the abstract machine, except as modified by the
unknown factors mentioned previously. 134) What constitutes an access to an object that
has volatile-qualified type is implementation-defined.
...
134) A volatile declaration may be used to describe an object corresponding to a memory-mapped
input/output port or an object accessed by an asynchronously interrupting function. Actions on
objects so declared shall not be ‘‘optimized out’’ by an implementation or reordered except as
permitted by the rules for evaluating expressions.
------------------------------------------------------------------
не ми стигнаха нервите, да търся какви са точно правилата за изчисление на изрази...