-1

In 64bit linux, sizeof(long), and sizeof(const char*) are same, I hope implement following code without specific additional argument(I mean don't specific type argument)

#define squeeze(smth) ({\
if (sizeof(smth) == sizeof(long)) {\
// do smth\
} else if (sizeof(smth) == sizeof(const char *)) {\
// do other\
}\
})
izhkymonte
  • 185
  • 1
  • 1
  • I'm not really sure what your question is. The standard specifies some rather loose requirements, but it definitely doesn't guarantee that the sizes of those two types will be equal. – user4520 Jan 19 '16 at 10:54
  • Why are you basing decisions on something like `sizeof(long)` vs `sizeof(const char *)`? Use the [predefined macros](https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html) for the memory model you're compiling for, which would normally be `LP64` or `ILP32` for GCC, assuming Linux. This situation is exactly what macros like that are predefined for. – Andrew Henle Jan 19 '16 at 10:56

1 Answers1

5

C11 introduces the _Generic keyword to do exactly what you are looking for.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Carl Norum
  • 219,201
  • 40
  • 422
  • 469