OT arm-gcc hadanka
Miroslav Šinko
sinkomiro na gmail.com
Pondělí Prosinec 29 16:35:41 CET 2014
On 29.12.2014 16:26, Jan Waclawek wrote:
>> 8 a 16?
>
> No, to by som bol prosil, preto je tam ten __attribute__((packed)) (aligned
> v tomto pripade je naozaj ignorovane, ako manual slubuje).
>
> Lenze...
>
>> 10, 20?
>
> Ved prave.
>
>
>>
>> S ARM-ami nerobim, predpokladam defaultne zarovnanie na 4 byty.
>
>
> No, lenze potom by sizeof(TBar) mal byt prinajmensom nasobok 4, nie?
Preco? TBar mas explicitne zarovnany na 1. Co nemas explicitne zarovnane
je union, ten bude zarovnavany na 4B. Jeho velkost je dana vacsou
polozkou, teda "uint16_t c[3]". 16-bit polozka sama osebe nema byt preco
natahovana na 4B, teda velkost c[3] je 6B. Ale union ako celok MUSI byt
doplneny paddingom na 4B zarovnanie, tu na 8B. No a v TBar to spolu s
"uint16_t a" vyjde na 10B.
> Takze druhe kolo, tipnite si, kolko je offsetof(TBar, b).
Tu by nemal byt problem: 2
miro
> wek
>
>
>
>
>>
>> On 29.12.2014 13:34, Jan Waclawek wrote:
>>> arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.8.3 20131129
>>> (release) [ARM/embedded-4_8-branch revision 205641]
>>>
>>> c:/PROGRA~1/ARMTools/launchpad.net_gcc-arm-embedded/bin/arm-none-eabi-gcc
>>> -c -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -I.
>>> -Wpadded -MD -MP -MF .dep/ch.o.d ch.c -o objdir/ch.o
>>>
>>>
>>> Aka je vysledna hodnota a a b?
>>>
>>> wek
>>>
>>>
>>> #include<stdint.h>
>>>
>>> typedef struct __attribute__((packed, aligned(1))) {
>>> uint16_t a;
>>> union {
>>> uint32_t b;
>>> uint16_t c[3];
>>> };
>>> } TBar;
>>>
>>> typedef struct __attribute__((packed)) {
>>> TBar a;
>>> TBar b;
>>> } TFoo;
>>>
>>>
>>> const uint32_t a = sizeof(TBar);
>>> const uint32_t b = sizeof(TFoo);
>>>
>>> int main(void) {
>>> }
>>>
Další informace o konferenci Hw-list