sizeofs.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <sys/types.h>
  2. #include <wctype.h>
  3. #include <wchar.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("int", sizeof(int), FALSE, TRUE);
  50. D("wchar_t", sizeof(wchar_t), FALSE, TRUE);
  51. D("wint_t", sizeof(wint_t), FALSE, TRUE);
  52. D("size_t", sizeof(size_t), FALSE, TRUE);
  53. D("mbstate_t", sizeof(mbstate_t), FALSE, TRUE);
  54. return 0;
  55. }