A
Andrey Vul
The "template":
#include <limits.h>
#define issignedtype(t) ((t)-1 < (t)0 ? 1 : 0)
#define _T_MAX(t) \
inline t t##_max() { \
t x = 0; \
if (issignedtype(t)) *((unsigned t*)&x) = \
(1ULL << (sizeof(t)*CHAR_BIT - 1)) - 1; \
else x = (t)-1; \
return x; \
}
When expanded with t=size_t,
inline size_t size_t_max() {
size_t x = 0;
if (((size_t)-1 < (size_t)0 ? 1 : 0))
*((unsigned size_t*)&x) = /* ERROR: missing ')' before size_t
* 'size_t': illegal use of this
type as an expression
* syntax error: ')' */
(1ULL << (sizeof(size_t)*8 - 1)) - 1;
else x = (size_t)-1;
return x; }
The expansion with t=int generates no errors.
Any solutions?
#include <limits.h>
#define issignedtype(t) ((t)-1 < (t)0 ? 1 : 0)
#define _T_MAX(t) \
inline t t##_max() { \
t x = 0; \
if (issignedtype(t)) *((unsigned t*)&x) = \
(1ULL << (sizeof(t)*CHAR_BIT - 1)) - 1; \
else x = (t)-1; \
return x; \
}
When expanded with t=size_t,
inline size_t size_t_max() {
size_t x = 0;
if (((size_t)-1 < (size_t)0 ? 1 : 0))
*((unsigned size_t*)&x) = /* ERROR: missing ')' before size_t
* 'size_t': illegal use of this
type as an expression
* syntax error: ')' */
(1ULL << (sizeof(size_t)*8 - 1)) - 1;
else x = (size_t)-1;
return x; }
The expansion with t=int generates no errors.
Any solutions?