[ros-dev] Re: Compiler-independence for 64-bit integral constants
Martin Fuchs
martin-fuchs at gmx.net
Sat Oct 9 17:32:19 CEST 2004
Hi,
> So, in the interest of fixing this once and for all, the only option is to
> name a macro to handle these compiler specifics in one place, and then use
> that macro when defining 64-bit integral constants. The question is then,
> what to name it? The macro will be defined something like (omitting unsigned
> here):
I already used the following defines: (in winefile and explorer)
#ifdef _MSC_VER
#define LONGLONGARG _T("I64")
#else
#define LONGLONGARG _T("L")
#endif
> #if defined __GNUC__
> #define ZZZ(X) X##LL
> #elif defined _MSC_VER
> #define ZZZ(X) X##i64
> #else
> #error Unknown compiler for 64-bit integral constant suffix
> #endif
> Serious suggestions that have surfaced so far are:
> DEFINE_INT64
> MAKE_INT64
May be we can combine this ideas to a new proposal:
#ifdef __GNUC__
#define FMT_INT64 _T("L")
#elif defined(_MSC_VER)
#define FMT_INT64 _T("I64")
#else
#error Unknown compiler for 64-bit integral constant suffix
#endif
"FMT" stands for "format string", I think this is a bit clearer than "DEFINE" or "MAKE".
This are some usage examples:
printf("%" FMT_INT64 "d", index); /* format 64 bit decimal integer */
sprintf(buffer, "%" FMT_INT64 "x", index); /* format 64 bit hex number, lower case */
sprintf(buffer, "%" FMT_INT64 "X", index); /* format 64 bit hex number, upper case */
_stprintf(buffer, TEXT("%") FMT_INT64 TEXT("X"), index); /* compatible both to UNICODE and ANSI builds */
Regards,
Martin
More information about the Ros-dev
mailing list