"Module":"alignof",
"Title":"alignof - ALIGNOF() macro to determine alignment of a type.",
"Author":"dinesh",
"Dependencies":[
{
"depends":"ccan/build_assert"
},
]
"Description":[
{
"str":""
},
{
"str":"Many platforms have requirements that certain types must be aligned"
},
{
"str":"to certain address boundaries, such as ints needing to be on 4-byte"
},
{
"str":"boundaries.  Attempting to access variables with incorrect"
},
{
"str":"alignment may cause performance loss or even program failure (eg. a"
},
{
"str":"bus signal)."
},
{
"str":""
},
{
"str":"There are times which it's useful to be able to programatically"
},
{
"str":"access these requirements, such as for dynamic allocators."
},
{
"str":""
},
{
"str":"Example:"
},
{
"str":"	#include <stdio.h>"
},
{
"str":"	#include "alignof/alignoff.h""
},
{
"str":""
},
{
"str":"	int main(int argc, char *argv[])"
},
{
"str":"	{"
},
{
"str":"		char arr[sizeof(int)];"
},
{
"str":""
},
{
"str":"		if ((unsigned long)arr % ALIGNOF(int)) {"
},
{
"str":"			printf("arr %p CANNOT hold an int\n", arr);"
},
{
"str":"			exit(1);"
},
{
"str":"		} else {"
},
{
"str":"			printf("arr %p CAN hold an int\n", arr);"
},
{
"str":"			exit(0);"
},
{
"str":"		}"
},
{
"str":"	}"
},
]
