sizeofs.c 1.8 KB

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