#pragma message
是一个预处理指令,用于在编译过程中向程序员发出消息或警告。这个指令通常用于在编译时向开发者提供一些有用的信息。
使用场景:编译时提示版本信息、时间信息、等等
#pragma message("Your message here") //编译时就可以输出"Your message here"
示例代码:
#include <string.h> #include <stdio.h> #include <stdlib.h> #define test_define "myname" #define PRINT_MACRO_HELPER(x) #x #define PRINT_MACRO(x) #x "=" PRINT_MACRO_HELPER(x) #define NUMBER_MACRO 3.14159 #define STRING_MACRO "This is a string." unsigned int debug_one = 1; int main(int args, char *argv[]) { #pragma message("Compiling " __FILE__) #pragma message("" __TIMESTAMP__) #pragma message("#test_define") #pragma message(PRINT_MACRO(NUMBER_MACRO)) #pragma message(PRINT_MACRO(STRING_MACRO)) #pragma message(PRINT_MACRO(UNDEF_MACRO)) // printf("test argv=%s, %s\n", argv[1], argv[2]); while(1) { sleep(2); // system("echo `pgrep a.out`"); //system("echo `ps -aux | grep a.out`"); //system("echo `ls a.out` >> /root/t24685/test/txt.txt"); debug_one = ((~(debug_one))&0x1); printf("test debug_one = %x \n", debug_one); } printf("test argv=%s, %s\n", argv[1], argv[2]); // printf("%d--%d\n",sizeof(size_t),sizeof(unsigned long)); return 0; }
输出结果:
1.c: In function ‘main’: 1.c:18:9: note: #pragma message: Compiling 1.c #pragma message("Compiling " __FILE__) ^ 1.c:19:9: note: #pragma message: Tue Oct 31 20:28:17 2023 #pragma message("" __TIMESTAMP__) ^ 1.c:20:9: note: #pragma message: #test_define #pragma message("#test_define") ^ 1.c:21:9: note: #pragma message: NUMBER_MACRO=3.14159 #pragma message(PRINT_MACRO(NUMBER_MACRO)) ^ 1.c:22:9: note: #pragma message: STRING_MACRO="This is a string." #pragma message(PRINT_MACRO(STRING_MACRO)) ^ 1.c:23:9: note: #pragma message: UNDEF_MACRO=UNDEF_MACRO #pragma message(PRINT_MACRO(UNDEF_MACRO)) ^
标签:__,MACRO,pragma,PRINT,message,预处理,define From: https://www.cnblogs.com/tzj-kernel/p/17801297.html