sizeofs.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netinet/in.h>
  4. #include <poll.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8. #define TABS "\t\t"
  9. #define FALSE (0)
  10. #define TRUE (1)
  11. static void D (const char *s, int sz, int set, int export)
  12. {
  13. int res;
  14. res = printf("%s%s", TABS, s);
  15. if (export) {
  16. res = printf("*");
  17. }
  18. res = printf(" = ");
  19. if (sz == 1) {
  20. res = printf("SHORTCHAR");
  21. } else if (sz == 2) {
  22. res = printf("SHORTINT");
  23. } else if (sz == 4) {
  24. if (set) {
  25. res = printf("SET");
  26. } else {
  27. res = printf("INTEGER");
  28. }
  29. } else if (sz == 8) {
  30. if (set) {
  31. res = printf("ARRAY [untagged] 2 OF SET");
  32. } else {
  33. res = printf("LONGINT");
  34. }
  35. } else {
  36. res = printf("ARRAY [untagged] ");
  37. if (sz % 4 == 0) {
  38. if (set) {
  39. res = printf("%d OF SET", sz / 4);
  40. } else {
  41. res = printf("%d OF INTEGER", sz / 4);
  42. }
  43. } else {
  44. res = printf("%d OF SHORTCHAR", sz);
  45. }
  46. }
  47. res = printf(";\n");
  48. }
  49. int main ()
  50. {\
  51. D("PtrVoid", sizeof(void *), FALSE, TRUE);
  52. D("short", sizeof(short), FALSE, TRUE);
  53. D("int", sizeof(int), FALSE, TRUE);
  54. D("intFlags", sizeof(int), TRUE, TRUE);
  55. D("size_t", sizeof(size_t), FALSE, TRUE);
  56. D("ssize_t", sizeof(ssize_t), FALSE, TRUE);
  57. D("time_t", sizeof(time_t), FALSE, TRUE);
  58. D("suseconds_t", sizeof(suseconds_t), FALSE, TRUE);
  59. D("socklen_t", sizeof(socklen_t), FALSE, TRUE);
  60. D("in_addr_t", sizeof(in_addr_t), FALSE, TRUE);
  61. D("in_port_t", sizeof(in_port_t), FALSE, TRUE);
  62. D("nfds_t", sizeof(nfds_t), FALSE, TRUE);
  63. D("sa_family_t", sizeof(sa_family_t), FALSE, TRUE);
  64. return 0;
  65. }