请通过。
#define _VERSION_ 1.4
#define DEFAULT_NETWORK_TOKEN_KEY { 3, 6, 5, 100}
// 我不能改变上面的宏但是下面
#define STR_VALUE(arg) #arg
#define FUNCTION_NAME(name) STR_VALUE(name\r)
#define TEST_FUNC #AP started v _VERSION_
#define TEST_FUNC_NAME FUNCTION_NAME(TEST_FUNC)
#define QUOTE_X(t)#t
#define QUOTE(t)QUOTE_X(t)
#define ABC 100 //{ 3, 6, 5, 100}
#define MYSTR "The value of ABC is"
const uint8 startMsg[] = MYSTR " " QUOTE(ABC);
结果:ABC的值为100
const uint8 startMsg[] = TEST_FUNC_NAME;
results: #AP started v 1.4 (Carriage return) // 我也想去掉 v 和 1.4 之间的空格
我想
const uint8 startMsg[] = ?? ;
应该导致#AP started [3.6.5.100] v1.4(回车)或#AP started [3,6,5,100] v1.4 (回车)或类似结果。
我正在开发 SOC 芯片,需要在启动时展示它。紧迫的。:)
------ 问题的答案是 ------
#define NETTOKENKEY(a,b,c,d) "[" #a "." #b "." #c "." #d "]"
#define GENNETTOKENKEY(z) NETTOKENKEY(z)
#define STRINGIZER(arg) #arg
#define STR_VALUE(arg) STRINGIZER(arg)
#define AP_VERSION_STR "#AP started v" STR_VALUE(_VERSION_)
#define AP_NETVERSION_STR "#AP started " \
GENNETTOKENKEY(DEFAULT_NETWORK_TOKEN_KEY_VALUES) \
" v" STR_VALUE(_VERSION_) **"\r"**
const uint8 startMsg[] = AP_NETVERSION_STR ;