_info 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * alignof - ALIGNOF() macro to determine alignment of a type.
  6. *
  7. * Many platforms have requirements that certain types must be aligned
  8. * to certain address boundaries, such as ints needing to be on 4-byte
  9. * boundaries. Attempting to access variables with incorrect
  10. * alignment may cause performance loss or even program failure (eg. a
  11. * bus signal).
  12. *
  13. * There are times which it's useful to be able to programatically
  14. * access these requirements, such as for dynamic allocators.
  15. *
  16. * Example:
  17. * #include <stdio.h>
  18. * #include <stdlib.h>
  19. * #include <ccan/alignof/alignof.h>
  20. *
  21. * int main(int argc, char *argv[])
  22. * {
  23. * char arr[sizeof(int)];
  24. *
  25. * if ((unsigned long)arr % ALIGNOF(int)) {
  26. * printf("arr %p CANNOT hold an int\n", arr);
  27. * exit(1);
  28. * } else {
  29. * printf("arr %p CAN hold an int\n", arr);
  30. * exit(0);
  31. * }
  32. * }
  33. *
  34. * License: LGPL (2 or any later version)
  35. * Author: Rusty Russell <rusty@rustcorp.com.au>
  36. */
  37. int main(int argc, char *argv[])
  38. {
  39. if (argc != 2)
  40. return 1;
  41. if (strcmp(argv[1], "depends") == 0) {
  42. printf("ccan/build_assert\n");
  43. return 0;
  44. }
  45. return 1;
  46. }