New preprocessor macroses for compiler verstion tests: __GNUC_LESS(maj,min), __GNUC_NOT_LESS(maj, min), __VISUAL_STUDIO_LESS(maj, min), __VISUAL_STUDIO_NOT_LESS(maj, min), __VISUAL_C_LESS(maj, min) and __VISUAL_C_NOT_LESS(maj, min)

This commit is contained in:
Stas Degteff 2011-02-20 16:19:32 +00:00
parent a1c4eeeeb1
commit 5e98926932
3 changed files with 67 additions and 7 deletions

View File

@ -30,6 +30,59 @@
#ifndef __gdefs_h #ifndef __gdefs_h
#define __gdefs_h #define __gdefs_h
/* ------------------------------------------------------------------
* Convenience macros to test the version of GNU C and C++ compiler
* Use them like this:
* #if __GNUC_NOT_LESS (4,0)
* ... code requiring gcc 4.0 or later ...
* #endif
* Note - they won't work for gcc1 or glibc1, since the _MINOR macros
* were not defined then.
*/
#if defined __GNUC__ && defined __GNUC_MINOR__
# define __GNUC_NOT_LESS(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
# define __GNUC_LESS(maj, min) (! __GNUC_NOT_LESS(maj, min) )
#else
# define __GNUC_NOT_LESS(maj, min) 0
# define __GNUC_LESS(maj, min) 0
#endif
/* ------------------------------------------------------------------
* Convenience macros to test the version of Visua Studio and
* macros to test the version of Visual C (cl.exe /? show it).
* Use them like this:
* #if __VISUAL_STUDIO_NOT_LESS (6,0)
* ... code requiring MS VS 6.0 or later ...
* #endif
*/
#if defined _MSC_VER
/* FIXME: This condition not tested anywhere, it is true for VS 6.0 and VS 4.2 and VS 5.0 */
/*
# define __VISUAL_STUDIO_NOT_LESS (maj, min) \
( (1000+ ((maj)-4)*100 + (min)*10) >= _MSC_VER )
*/
/* FIXME: This condition not tested anywhere, it is true for VS 4.2, 5.0, 6.0 and VS2005 (VC++ 8.0) */
# define __VISUAL_STUDIO_NOT_LESS(maj, min) \
( (maj==4)? ((1000+(min)*10)>=_MSC_VER) : \
( (maj==5)? ((1100+(min)*10)>=_MSC_VER) : \
( (maj==6)? ((1200+(min)*10)>=_MSC_VER) : \
( (maj==7)? ((1300+(min)*10)>=_MSC_VER) : \
( (maj==8)? ((1400+(min)*10)>=_MSC_VER) : \
( (maj==9)? ((1500+(min)*10)>=_MSC_VER) : \
0 \
) ) ) ) ) )
# define __VISUAL_C_NOT_LESS(maj, min) \
( _MSC_VER >= ((maj*100) + (min)) )
# define __VISUAL_STUDIO_LESS(maj, min) (! __VISUAL_STUDIO_NOT_LESS(maj, min) )
# define __VISUAL_C_LESS(maj, min) (! __VISUAL_C_NOT_LESS(maj, min) )
#else
# define __VISUAL_STUDIO_NOT_LESS(maj, min) 0
# define __VISUAL_STUDIO_LESS(maj, min) 0
# define __VISUAL_C_NOT_LESS(maj, min) 0
# define __VISUAL_C_LESS(maj, min) 0
#endif
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_MALLOC_H #ifdef HAVE_MALLOC_H

View File

@ -45,7 +45,8 @@
#ifdef __WIN32__ #ifdef __WIN32__
#include <windows.h> #include <windows.h>
#endif #endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400) #if __VISUAL_C_NOT_LESS(14,0)
//#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#include <time.h> #include <time.h>
#endif #endif
@ -130,7 +131,8 @@ extern const char* gmonths[];
inline void ggmtime(struct tm *_tm, const time32_t *timep) inline void ggmtime(struct tm *_tm, const time32_t *timep)
{ {
const time_t temp(*timep); const time_t temp(*timep);
#if defined(_MSC_VER) && (_MSC_VER >= 1400) #if __VISUAL_C_NOT_LESS(14,0)
//#if defined(_MSC_VER) && (_MSC_VER >= 1400)
if (0 != gmtime_s(_tm, &temp)) if (0 != gmtime_s(_tm, &temp))
{ {
const time_t zero(0); const time_t zero(0);
@ -152,7 +154,8 @@ inline void ggmtime(struct tm *_tm, const time32_t *timep)
inline void glocaltime(struct tm *_tm, const time32_t *timep) inline void glocaltime(struct tm *_tm, const time32_t *timep)
{ {
const time_t temp(*timep); const time_t temp(*timep);
#if defined(_MSC_VER) && (_MSC_VER >= 1400) #if __VISUAL_C_NOT_LESS(14,0)
//#if defined(_MSC_VER) && (_MSC_VER >= 1400)
if (0 != localtime_s(_tm, &temp)) if (0 != localtime_s(_tm, &temp))
{ {
const time_t zero(0); const time_t zero(0);
@ -174,7 +177,8 @@ inline void glocaltime(struct tm *_tm, const time32_t *timep)
inline void gctime(TCHAR *buffer, size_t sizeInChars, const time32_t *timep) inline void gctime(TCHAR *buffer, size_t sizeInChars, const time32_t *timep)
{ {
const time_t temp(*timep); const time_t temp(*timep);
#if defined(_MSC_VER) && (_MSC_VER >= 1400) #if __VISUAL_C_NOT_LESS(14,0)
//#if defined(_MSC_VER) && (_MSC_VER >= 1400)
if (0 != _tctime_s(buffer, sizeInChars, &temp)) if (0 != _tctime_s(buffer, sizeInChars, &temp))
{ {
const time_t zero(0); const time_t zero(0);
@ -207,7 +211,8 @@ inline time32_t gmktime(struct tm *timep)
#if defined(__OS2__) #if defined(__OS2__)
inline void usleep(int duration) { DosSleep(duration); } inline void usleep(int duration) { DosSleep(duration); }
#elif (defined(__MINGW32__) && __GNUC__*100+__GNUC_MINOR__ < 304) || defined(_MSC_VER) #elif (defined(__MINGW32__) && __GNUC_LESS(3,4)) || defined(_MSC_VER)
//#elif (defined(__MINGW32__) && __GNUC__*100+__GNUC_MINOR__ < 304) || defined(_MSC_VER)
inline void usleep(long duration) { Sleep(duration); } inline void usleep(long duration) { Sleep(duration); }
#endif #endif

View File

@ -31,7 +31,8 @@
#if defined(__WIN32__) #if defined(__WIN32__)
#include <windows.h> #include <windows.h>
#if defined(_MSC_VER) && (_MSC_VER >= 1400) #if __VISUAL_C_NOT_LESS(14,0)
//#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#include <intrin.h> #include <intrin.h>
#endif #endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
@ -55,7 +56,8 @@
#else #else
// ------------------------------------------------------------------ // ------------------------------------------------------------------
#if defined(_MSC_VER) && (_MSC_VER < 1400) #if __VISUAL_C_LESS(14,0)
//#if defined(_MSC_VER) && (_MSC_VER < 1400)
static void __cpuid(int CPUInfo[4], int cpuidfun) static void __cpuid(int CPUInfo[4], int cpuidfun)
{ {
__asm __asm