Skip to content

Instantly share code, notes, and snippets.

@vu3rdd
Last active December 28, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vu3rdd/7445863 to your computer and use it in GitHub Desktop.
Save vu3rdd/7445863 to your computer and use it in GitHub Desktop.
ARM gcc structure alignment
#ifndef TEST_DEFINED
#define TEST_DEFINED
#define OFFSET(x, y) &((x *)0)->y
typedef unsigned int __u32;
typedef int __s32;
typedef long long __s64;
typedef unsigned char __u8;
#endif
#include "test.h"
#include <stdio.h>
#include <time.h>
struct v4l2_event_vsync {
/* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */
__u8 field;
} __attribute__ ((packed));
struct v4l2_event {
__u32 type;
union {
struct v4l2_event_vsync vsync;
__u8 data[64];
} u;
__u32 pending;
__u32 sequence;
struct timespec timestamp;
__u32 reserved[9];
};
int main() {
printf("sizeof v4l2_event = %d\n", sizeof(struct v4l2_event));
printf("offsets of structure members\n");
printf("offset of \'type\' = %d\n", (int)OFFSET(struct v4l2_event, type));
printf("offset of \'u\' = %d\n", (int)OFFSET(struct v4l2_event, u));
printf("offset of \'pending\' = %d\n", (int)OFFSET(struct v4l2_event, pending));
printf("offset of \'sequence\' = %d\n", (int)OFFSET(struct v4l2_event, sequence));
printf("offset of \'timestamp\' = %d\n", (int)OFFSET(struct v4l2_event, timestamp));
printf("offset of \'reserved\' = %d\n", (int)OFFSET(struct v4l2_event, reserved));
return 0;
}
#include "test.h"
#include <stdio.h>
#include <time.h>
struct v4l2_event_vsync {
/* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */
__u8 field;
} __attribute__ ((packed));
struct v4l2_event_ctrl {
__u32 changes;
__u32 type;
union {
__s32 value;
__s64 value64;
};
__u32 flags;
__s32 minimum;
__s32 maximum;
__s32 step;
__s32 default_value;
};
struct v4l2_event_frame_sync {
__u32 frame_sequence;
};
struct v4l2_event {
__u32 type;
union {
struct v4l2_event_vsync vsync;
struct v4l2_event_ctrl ctrl;
struct v4l2_event_frame_sync frame_sync;
__u8 data[64];
} u;
__u32 pending;
__u32 sequence;
struct timespec timestamp;
__u32 id;
__u32 reserved[8];
};
int main() {
printf("sizeof v4l2_event = %d\n", sizeof(struct v4l2_event));
printf("sizeof v4l2_event_ctrl = %d\n", sizeof(struct v4l2_event_ctrl));
printf("offsets of structure members\n");
printf("offset of \'type\' = %d\n", (int)OFFSET(struct v4l2_event, type));
printf("offset of \'u\' = %d\n", (int)OFFSET(struct v4l2_event, u));
printf("offset of \'pending\' = %d\n", (int)OFFSET(struct v4l2_event, pending));
printf("offset of \'sequence\' = %d\n", (int)OFFSET(struct v4l2_event, sequence));
printf("offset of \'timestamp\' = %d\n", (int)OFFSET(struct v4l2_event, timestamp));
printf("offset of \'id\' = %d\n", (int)OFFSET(struct v4l2_event, id));
printf("offset of \'reserved\' = %d\n", (int)OFFSET(struct v4l2_event, reserved));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment