Created
August 15, 2017 03:14
-
-
Save liyang85105/f8623014bb9a6d9bf0f6a6183666053b to your computer and use it in GitHub Desktop.
print macro(#define macro ...)'s value when using gcc/g++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Some test definition here */ | |
#define DEFINED_BUT_NO_VALUE | |
#define DEFINED_INT 3 | |
#define DEFINED_STR "ABC" | |
/* definition to expand macro then apply to pragma message */ | |
#define VALUE_TO_STRING(x) #x | |
#define VALUE(x) VALUE_TO_STRING(x) | |
#define VAR_NAME_VALUE(var) #var "=" VALUE(var) | |
/* Some example here */ | |
#pragma message(VAR_NAME_VALUE(NOT_DEFINED)) | |
#pragma message(VAR_NAME_VALUE(DEFINED_BUT_NO_VALUE)) | |
#pragma message(VAR_NAME_VALUE(DEFINED_INT)) | |
#pragma message(VAR_NAME_VALUE(DEFINED_STR)) | |
Above definitions result in: | |
test.c:10:9: note: #pragma message: NOT_DEFINED=NOT_DEFINED | |
test.c:11:9: note: #pragma message: DEFINED_BUT_NO_VALUE= | |
test.c:12:9: note: #pragma message: DEFINED_INT=3 | |
test.c:13:9: note: #pragma message: DEFINED_STR="ABC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solved my problem. Thank you!