It just occurred to me that I should state that all this abstraction is zero-cost by checking what the output is. Indeed it is:
movl _y, %eax movl _x, %ecx movl %ecx, _y movl %eax, _x
But clang tells me this:
test.c:13:22: warning: unsequenced modification and access to 'y' [-Wunsequenced] .second = (y = x)
I had ever so confidently said that the order was guaranteed because I read this from the standard:
> 6.7.9.19: The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject; all subobjects that are not initialized explicitly shall be initialized implicitly the same as objects that have static storage duration
Clang seems to disagree. Anyone have any ideas? This is the postprocessed (-E
) output of the call to swap
:
((void)((x) = ((struct { typeof((y)) first; typeof((y) = (x)) second; }) { .first = ((y)), .second = ((y) = (x)) }.first)));
Which cleaned up is (I think):
x = (struct { char* first; char* second; }) { .first = y, .second = (y = x) }.first;
Same error when I try that version. GCC on the hand is happy with it. So, am I missing something or is this a compiler bug?
Embedded C the dialect is just ISO C with some spare bits like _Fract
and _Accum
, and maybe some (nonstandard, compiler-specific) recursion limitations for the tiniest/tinniest chips; you’re best off reading the extension Standard {pdf} and compiler documentation.
OpenCL C {pdf} is arguably another embedded C dialect, but it’s not capital-E Embedded C.
In either case, you probably don’t need a book; if you’re familiar enough with C to work from the standard/extension PDFs, you’re good from here on out.
What makes you think that is so? The concept of the stack is an implementation detail and is not mentioned anywhere in the standard.
An object in C is simply defined as:
> 3.14 object: region of data storage in the execution environment, the contents of which can represent values
Notice nowhere it says anything about storage duration. If you know otherwise, I'm all ears but I would appreciate if you could point to the proper paragraph in the C99 Standard which backs up your statement.