aboutsummaryrefslogtreecommitdiffstats
path: root/test/native/alignment_test.c
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-17 17:15:41 +0200
committerSven Gothel <[email protected]>2011-07-17 17:15:41 +0200
commit133de98defb7ec3d1f202805505aa85a5650e3d0 (patch)
tree6de2c4da3111755167e5ea0bac4c269e2a3b87e8 /test/native/alignment_test.c
parentad3dc39ccfddb007c3e91acf454f804573969419 (diff)
Add native alignment test c-code
Diffstat (limited to 'test/native/alignment_test.c')
-rw-r--r--test/native/alignment_test.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/native/alignment_test.c b/test/native/alignment_test.c
new file mode 100644
index 0000000..2762d3a
--- /dev/null
+++ b/test/native/alignment_test.c
@@ -0,0 +1,65 @@
+
+#include <stdio.h>
+#include <stdint.h>
+
+typedef struct {
+ int8_t c1;
+ int8_t v;
+} struct_alignment_int8;
+
+typedef struct {
+ int8_t c1;
+ int16_t v;
+} struct_alignment_int16;
+
+typedef struct {
+ int8_t c1;
+ int32_t v;
+} struct_alignment_int32;
+
+typedef struct {
+ int8_t c1;
+ int64_t v;
+} struct_alignment_int64;
+
+typedef struct {
+ int8_t c1;
+ long v;
+} struct_alignment_long;
+
+typedef struct {
+ int8_t c1;
+ void * v;
+} struct_alignment_pointer;
+
+typedef struct {
+ int8_t c1;
+ float v;
+} struct_alignment_float;
+
+typedef struct {
+ int8_t c1;
+ double v;
+} struct_alignment_double;
+
+typedef struct {
+ char c1;
+ long double v;
+} struct_alignment_longdouble;
+
+size_t padding(size_t totalsize, size_t typesize) { return totalsize - typesize - sizeof(char); }
+size_t alignment(size_t totalsize, size_t typesize) { return totalsize - typesize; }
+
+int main(int argc, char * argv[] ) {
+ printf("sizeof/alignment int8_t: %d / %d / %d\n", sizeof(int8_t), sizeof( struct_alignment_int8 ), alignment(sizeof( struct_alignment_int8 ), sizeof(int8_t)));
+ printf("sizeof/alignment int16_t: %d / %d / %d\n", sizeof(int16_t), sizeof( struct_alignment_int16 ), alignment(sizeof( struct_alignment_int16 ), sizeof(int16_t)));
+ printf("sizeof/alignment int32_t: %d / %d / %d\n", sizeof(int32_t), sizeof( struct_alignment_int32 ), alignment(sizeof( struct_alignment_int32 ), sizeof(int32_t)));
+ printf("sizeof/alignment int64_t: %d / %d / %d\n", sizeof(int64_t), sizeof( struct_alignment_int64 ), alignment(sizeof( struct_alignment_int64 ), sizeof(int64_t)));
+ printf("sizeof/alignment long: %d / %d / %d\n", sizeof(long), sizeof( struct_alignment_long ), alignment(sizeof( struct_alignment_long ), sizeof(long)));
+ printf("sizeof/alignment pointer: %d / %d / %d\n", sizeof(void *), sizeof( struct_alignment_pointer ), alignment(sizeof( struct_alignment_pointer ), sizeof(void *)));
+ printf("sizeof/alignment float: %d / %d / %d\n", sizeof(float), sizeof( struct_alignment_float ), alignment(sizeof( struct_alignment_float ), sizeof(float)));
+ printf("sizeof/alignment double: %d / %d / %d\n", sizeof(double), sizeof( struct_alignment_double ), alignment(sizeof( struct_alignment_double ), sizeof(double)));
+ printf("sizeof/alignment long double: %d / %d / %d\n", sizeof(long double), sizeof( struct_alignment_longdouble ), alignment(sizeof( struct_alignment_longdouble ), sizeof(long double)));
+
+ return 0;
+}