aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/attribs1.c
blob: 21d7556c21b28dbab957025269c9cea9c2f76421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* gcc-style "aligned" and "section" attributes */

/* Caveat: some C standard libraries, when preprocessed with -U__GNUC__,
   #define away __attribute__, so we use __attribute in the following. */

#include <stdio.h>

/* Alignment */

char filler1 = 1;
__attribute((__aligned__(16))) int a = 1234;
char filler2 = 1;
__attribute((__aligned__(8))) char b = 'b';

/* Sections */

__attribute((__section__("mydata"))) int c = 78;
char filler3 = 1;
__attribute((__section__("mydata"))) int d = 90;

__attribute((__section__("myconst"))) const int e = 12;
const char filler4 = 1;
__attribute((__section__("myconst"))) const int f = 34;

__attribute((__section__("mycode"))) int myfunc(int x) { return x + 1; }

/* Test harness */

int main()
{
  printf("Address of a = %u mod 16\n", ((unsigned int) &a) & 0xF);
  printf("Address of b = %u mod 8\n", ((unsigned int) &b) & 0x7);
  printf("Delta d - c = %u\n", ((unsigned int) &d) - ((unsigned int) &c));
  printf("Delta f - e = %u\n", ((unsigned int) &f) - ((unsigned int) &e));
  return 0;
}