1 /**************************************************************************/ 2 /* */ 3 /* OCaml */ 4 /* */ 5 /* Contributed by Sylvain Le Gall for Lexifi */ 6 /* */ 7 /* Copyright 2008 Institut National de Recherche en Informatique et */ 8 /* en Automatique. */ 9 /* */ 10 /* All rights reserved. This file is distributed under the terms of */ 11 /* the GNU Lesser General Public License version 2.1, with the */ 12 /* special exception on linking described in the file LICENSE. */ 13 /* */ 14 /**************************************************************************/ 15 16 #ifdef DEBUG 17 18 #include <stdio.h> 19 #include <windows.h> 20 21 /* According to MSDN, MSVC supports the gcc ## operator (to deal with empty 22 argument lists) 23 */ 24 #define DEBUG_PRINT(fmt, ...) \ 25 do \ 26 { \ 27 if (debug_test()) \ 28 { \ 29 fprintf(stderr, "DBUG (pid:%ld, tid: %ld): ", GetCurrentProcessId(), \ 30 GetCurrentThreadId()); \ 31 fprintf(stderr, fmt, ##__VA_ARGS__); \ 32 fprintf(stderr, "\n"); \ 33 fflush(stderr); \ 34 }; \ 35 } while(0) 36 37 /* Test if we are in dbug mode */ 38 int debug_test (void); 39 40 #elif defined(_MSC_VER) && _MSC_VER < 1300 41 42 #define DEBUG_PRINT(fmt) 43 44 /* __pragma wasn't added until Visual C++ .NET 2002, so simply disable the 45 warning entirely 46 */ 47 48 #pragma warning (disable:4002) 49 50 #elif defined(_MSC_VER) && _MSC_VER <= 1400 51 52 /* Not all versions of the Visual Studio 2005 C Compiler (Version 14) support 53 variadic macros, hence the test for this branch being <= 1400 rather than 54 < 1400. 55 This convoluted pair of macros allow DEBUG_PRINT to remain while temporarily 56 suppressing the warning displayed for a macro called with too many 57 parameters. 58 */ 59 #define DEBUG_PRINT_S(fmt) __pragma(warning(pop)) 60 #define DEBUG_PRINT \ 61 __pragma(warning(push)) \ 62 __pragma(warning(disable:4002)) \ 63 DEBUG_PRINT_S 64 65 #else 66 67 /* Visual Studio supports variadic macros in all versions from 2008 (CL 15). */ 68 #define DEBUG_PRINT(fmt, ...) 69 70 #endif 71