File: tryunaligned.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,500 kB
  • sloc: ansic: 15,824; perl: 674; sh: 63; makefile: 29
file content (17 lines) | stat: -rw-r--r-- 591 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int test_short(char* ptr);
int test_int(char* ptr);
int test_long(char* ptr);
int test_longlong(char* ptr);
int main(void)
{
  long buf[2] = {0,0};		/* will be aligned */
  char* ptr = ((char*)buf) + 1; /* will be unaligned */
  return (test_short(ptr) +
	  test_int(ptr) +
	  test_long(ptr) +
	  test_longlong(ptr)) == 10 ? 0 : 1;
}
int test_short(char* ptr) { return ++*((unsigned short*)ptr); }
int test_int(char* ptr) { return ++*((unsigned int*)ptr); }
int test_long(char* ptr) { return ++*((unsigned long*)ptr); }
int test_longlong(char* ptr) { return ++*((unsigned long long*)ptr); }