1 head 1.1;
2 access;
3 symbols;
4 locks
5 baker:1.1; strict;
6 comment @ * @;
7
8
9 1.1
10 date 2008.05.06.23.08.13; author baker; state Exp;
11 branches;
12 next ;
13
14
15 desc
16 @@
17
18
19 1.1
20 log
21 @Initial revision
22 @
23 text
24 @/*
25 * dataalign.c -- show alignment needs
26 *
27 * Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet
28 * Copyright (C) 2001 O'Reilly & Associates
29 *
30 * The source code in this file can be freely used, adapted,
31 * and redistributed in source or binary form, so long as an
32 * acknowledgment appears in derived source files. The citation
33 * should list that the code comes from the book "Linux Device
34 * Drivers" by Alessandro Rubini and Jonathan Corbet, published
35 * by O'Reilly & Associates. No warranty is attached;
36 * we cannot take responsibility for errors or fitness for use.
37 *
38 * This runs with any Linux kernel (not any Unix, because of <linux/types.h>)
39 */
40 #include <stdio.h>
41 #include <sys/utsname.h>
42 #include <linux/types.h>
43
44 /*
45 * Define several data structures, all of them start with a lone char
46 * in order to present an unaligned offset for the next field
47 */
48 struct c {char c; char t;} c;
49 struct s {char c; short t;} s;
50 struct i {char c; int t;} i;
51 struct l {char c; long t;} l;
52 struct ll {char c; long long t;} ll;
53 struct p {char c; void * t;} p;
54 struct u1b {char c; __u8 t;} u1b;
55 struct u2b {char c; __u16 t;} u2b;
56 struct u4b {char c; __u32 t;} u4b;
57 struct u8b {char c; __u64 t;} u8b;
58
59 int main(int argc, char **argv)
60 {
61 struct utsname name;
62
63 uname(&name); /* never fails :) */
64 printf("arch Align: char short int long ptr long-long "
65 " u8 u16 u32 u64\n");
66 printf( "%-12s %3i %3i %3i %3i %3i %3i "
67 "%3i %3i %3i %3i\n",
68 name.machine,
69 /* note that gcc can subtract void * values, but it's not ansi */
70 (int)((void *)(&c.t) - (void *)&c),
71 (int)((void *)(&s.t) - (void *)&s),
72 (int)((void *)(&i.t) - (void *)&i),
73 (int)((void *)(&l.t) - (void *)&l),
74 (int)((void *)(&p.t) - (void *)&p),
75 (int)((void *)(&ll.t) - (void *)&ll),
76 (int)((void *)(&u1b.t) - (void *)&u1b),
77 (int)((void *)(&u2b.t) - (void *)&u2b),
78 (int)((void *)(&u4b.t) - (void *)&u4b),
79 (int)((void *)(&u8b.t) - (void *)&u8b));
80 return 0;
81 }
82 @
|
This page was automatically generated by the
LXR engine.
|