2
0

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