sizeofs.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <sys/types.h>
  2. #include <sys/signal.h>
  3. #include <setjmp.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #define TABS "\t\t"
  7. #define FALSE (0)
  8. #define TRUE (1)
  9. static void D (const char *s, int sz, int set, int export)
  10. {
  11. int res;
  12. res = printf("%s%s", TABS, s);
  13. if (export) {
  14. res = printf("*");
  15. }
  16. res = printf(" = ");
  17. if (sz == 1) {
  18. res = printf("SHORTCHAR");
  19. } else if (sz == 2) {
  20. res = printf("SHORTINT");
  21. } else if (sz == 4) {
  22. if (set) {
  23. res = printf("SET");
  24. } else {
  25. res = printf("INTEGER");
  26. }
  27. } else if (sz == 8) {
  28. if (set) {
  29. res = printf("ARRAY [untagged] 2 OF SET");
  30. } else {
  31. res = printf("LONGINT");
  32. }
  33. } else {
  34. res = printf("ARRAY [untagged] ");
  35. if (sz % 4 == 0) {
  36. if (set) {
  37. res = printf("%d OF SET", sz / 4);
  38. } else {
  39. res = printf("%d OF INTEGER", sz / 4);
  40. }
  41. } else {
  42. res = printf("%d OF SHORTCHAR", sz);
  43. }
  44. }
  45. res = printf(";\n");
  46. }
  47. int main ()
  48. {
  49. D("PtrVoid", sizeof(void *), FALSE, TRUE);
  50. D("int", sizeof(int), FALSE, TRUE);
  51. D("long", sizeof(long), FALSE, TRUE);
  52. D("ulong", sizeof(unsigned long), FALSE, TRUE);
  53. D("size_t", sizeof(size_t), FALSE, TRUE);
  54. D("ssize_t", sizeof(ssize_t), FALSE, TRUE);
  55. D("off_t", sizeof(off_t), FALSE, TRUE);
  56. D("clock_t", sizeof(clock_t), FALSE, TRUE);
  57. D("clockid_t", sizeof(clockid_t), FALSE, TRUE);
  58. D("time_t", sizeof(time_t), FALSE, TRUE);
  59. D("mode_t", sizeof(mode_t), TRUE, TRUE);
  60. D("pid_t", sizeof(pid_t), FALSE, TRUE);
  61. D("uid_t", sizeof(uid_t), FALSE, TRUE);
  62. D("gid_t", sizeof(gid_t), FALSE, TRUE);
  63. D("dev_t", sizeof(dev_t), FALSE, TRUE);
  64. D("ino_t", sizeof(ino_t), FALSE, TRUE);
  65. D("nlink_t", sizeof(nlink_t), FALSE, TRUE);
  66. D("blkcnt_t", sizeof(blkcnt_t), FALSE, FALSE);
  67. D("blksize_t", sizeof(blksize_t), FALSE, FALSE);
  68. D("int8_t", sizeof(int8_t), FALSE, TRUE);
  69. D("uint8_t", sizeof(u_int8_t), FALSE, TRUE);
  70. D("int16_t", sizeof(int16_t), FALSE, TRUE);
  71. D("uint16_t", sizeof(u_int16_t), FALSE, TRUE);
  72. D("int32_t", sizeof(int32_t), FALSE, TRUE);
  73. D("uint32_t", sizeof(u_int32_t), FALSE, TRUE);
  74. D("int64_t", sizeof(int64_t), FALSE, TRUE);
  75. D("uint64_t", sizeof(u_int64_t), FALSE, TRUE);
  76. D("wchar_t", sizeof(wchar_t), FALSE, TRUE);
  77. D("sigjmp_buf", sizeof(sigjmp_buf), FALSE, TRUE);
  78. D("intFlags", sizeof(int), TRUE, TRUE);
  79. /* D("FILE", sizeof(FILE), FALSE, FALSE); */
  80. D("fflags_t", sizeof(fflags_t), TRUE, TRUE);
  81. printf("%ssigset_t* = ARRAY [untagged] %d OF BYTE;\n", TABS, (int)sizeof(sigset_t));
  82. printf("%sPtrSigset_t* = POINTER [untagged] TO sigset_t;\n", TABS);
  83. return 0;
  84. }