[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
__packed__ attribute ignored
From: |
Helge Kruse |
Subject: |
__packed__ attribute ignored |
Date: |
Thu, 31 Dec 2020 11:17:59 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 |
While compiling an open source project (https://sigrok.org/) I
experience invalida code generated by MXE. It looks like the
__attribute__((__packed__))
is ignored for a structure. Here is the complete code to reproduce the
behavior:
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
typedef struct sample_config {
uint32_t sample_depth;
uint32_t psa;
uint16_t u1;
uint32_t u2;
uint16_t clock_divisor;
} __attribute__((__packed__)) sample_config_t;
int main(int argc, char **argv)
{
sample_config_t *pcfg = 0;
printf("offset psa %lu\n", offsetof(sample_config_t,psa));
printf("offset u1 %lu\n", offsetof(sample_config_t,u1));
printf("offset u2 %lu\n", offsetof(sample_config_t,u2));
printf("offset clock_divisor %lu\n",
offsetof(sample_config_t,clock_divisor));
}
The offset should be 4, 8, 10, 14, what can be verified with a normal
GCC build. The MX compiler for i686 and x86_64 uses offsets of 4, 8, 12,
16. i.e. it doesn't pack the structure.
$ $HOME/mxe-git/usr/bin/x86_64-w64-mingw32.static.posix-gcc --version
x86_64-w64-mingw32.static.posix-gcc (GCC) 5.5.0
How should that be fixed?
Best regards,
Helge
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- __packed__ attribute ignored,
Helge Kruse <=