#include <windows.h> #include <iostream> #define STRING2(x) #x #define STRING(x) STRING2(x) #define FCC(ch4) ((((DWORD)(ch4) & 0xFF) << 24) | \ (((DWORD)(ch4) & 0xFF00) << 8) | \ (((DWORD)(ch4) & 0xFF0000) >> 8) | \ (((DWORD)(ch4) & 0xFF000000) >> 24)); int main() { const int rien = FCC(555); #pragma message (__FILE__ "[" STRING(__LINE__) "]: test") #pragma message(STRING(FCC(555))) #pragma message(STRING(rien))
#include <iostream> // DWORD not exist on Unix, let's alias it :). Remove this line on Windows. #define DWORD unsigned long int #define STRING2(x) #x #define STRING(x) STRING2(x) #define FCC(ch4) ((((DWORD)(ch4) & 0xFF) << 24) | \ (((DWORD)(ch4) & 0xFF00) << 8) | \ (((DWORD)(ch4) & 0xFF0000) >> 8) | \ (((DWORD)(ch4) & 0xFF000000) >> 24)); #define RIEN FCC(555) int main() { const int rien = RIEN; #pragma message (__FILE__ "[" STRING(__LINE__) "]: test") #pragma message(STRING(FCC(555))) #pragma message(STRING(RIEN)) #pragma message(STRING(rien)) std::cout << rien << std::endl; return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include <iostream> #define DWORD unsigned long int template <DWORD N> struct MSG { MSG() { int i; int d = i; // Provoque un warning uninitialized volontairement. } }; #define FCC(ch4) ((((DWORD)(ch4)&0xFF) << 24) | \ (((DWORD)(ch4)&0xFF00) << 8) | \ (((DWORD)(ch4)&0xFF0000) >> 8) | \ (((DWORD)(ch4)&0xFF000000) >> 24)) #define MESSAGE(expr) MSG<expr>() int main() { MESSAGE(4 + 5); MESSAGE(FCC(555)); return 0; }
g++ masm.cc -std=c++11 -Wuninitialized
masm.cc:11:13: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
int d = i;
^
masm.cc:24:3: note: in instantiation of member function 'MSG<9>::MSG' requested here
MESSAGE(4 + 5);
^
masm.cc:20:23: note: expanded from macro 'MESSAGE'
#define MESSAGE(expr) MSG<expr>()
^
masm.cc:10:10: note: initialize the variable 'i' to silence this warning
int i;
^
= 0
masm.cc:11:13: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
int d = i;
^
masm.cc:25:3: note: in instantiation of member function 'MSG<721551360>::MSG' requested here
MESSAGE(FCC(555));
^
masm.cc:20:23: note: expanded from macro 'MESSAGE'
#define MESSAGE(expr) MSG<expr>()
^
masm.cc:10:10: note: initialize the variable 'i' to silence this warning
int i;
^
= 0
2 warnings generated.
#include <iostream> #define DWORD unsigned long int #define FCC(ch4) ((((DWORD)(ch4)&0xFF) << 24) | \ (((DWORD)(ch4)&0xFF00) << 8) | \ (((DWORD)(ch4)&0xFF0000) >> 8) | \ (((DWORD)(ch4)&0xFF000000) >> 24)) template <DWORD N> struct MSG { static const bool val = false; }; #define MESSAGE(expr) static_assert(MSG<expr>::val, #expr) int main() { MESSAGE(4 + 5); MESSAGE(FCC(555)); }
masm.cc:20:3: error: static_assert failed due to requirement 'MSG<7>::val' "3 + 4"
MESSAGE(3 + 4);
^~~~~~~~~~~~~~
masm.cc:16:23: note: expanded from macro 'MESSAGE'
#define MESSAGE(expr) static_assert(MSG<expr>::val, #expr)
^ ~~~~~~~~~~~~~~
masm.cc:21:3: error: static_assert failed due to requirement 'MSG<721551360>::val' "FCC(555)"
MESSAGE(FCC(555));
^~~~~~~~~~~~~~~~~
masm.cc:16:23: note: expanded from macro 'MESSAGE'
#define MESSAGE(expr) static_assert(MSG<expr>::val, #expr)
^ ~~~~~~~~~~~~~~
2 errors generated.
#define STRING2(x) #x
#define STRING(x) STRING2(x)
#include <iostream> #define _STR(x) #x #define STR(x) _STR(x) #define ADD(a, b) a + b int main() { std::cout << _STR(ADD(3, 4)) << std::endl; // ADD(3, 4) std::cout << STR(ADD(3, 4)) << std::endl; // 3 + 4 }