PSTR如何接收多个不以逗号分隔的字符串
How can PSTR receive multiple strings not separated by commas?
我正在研究Arduino的ENC28J60库的rbb_server示例中的代码(如果可以的话,我会把链接放在这里),我注意到了下面的一段代码:
static word homePage() {
long t = millis() / 1000;
word h = t / 3600;
byte m = (t / 60) % 60;
byte s = t % 60;
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OKrn"
"Content-Type: text/htmlrn"
"Pragma: no-cachern"
"rn"
"<meta http-equiv='refresh' content='1'/>"
"<title>RBBB server</title>"
"<h1>$D$D:$D$D:$D$D</h1>"),
h/10, h%10, m/10, m%10, s/10, s%10);
return bfill.position();
}
如果字符串之间没有逗号分隔,PSTR(…………)怎么能编译??
我一直在寻找PSTR宏定义,我发现了这个:
Used to declare a static pointer to a string in program space. */
# define PSTR(s) ((const PROGMEM char *)(s))
#else /* !DOXYGEN */
/* The real thing. */
# define PSTR(s) (__extension__({static char __c[] PROGMEM = (s); &__c[0];}))
#endif /* DOXYGEN */
您可以在Arduino的IDE文件夹中的pgmspace.h文件中找到。
这怎么能编译??
谢谢!
C(C99,6.4.5p4)中有一条规则,规定两个相邻的字符串文字(无论它们在不同的行上):
"HTTP/1.0 200 OKrn"
"Content-Type: text/htmlrn"
连接成一个字符串文字,相当于:
"HTTP/1.0 200 OKrnContent-Type: text/htmlrn"
这是由预处理器在翻译阶段6中完成的。
编译器会自动将相邻的字符串文字连接为单个字符串文字。
printf("H" "e" "l" "l" "o");
相当于
printf("Hello");
相关文章:
- 如何分隔字符串并将标记传递给方法
- C++ 用空格和逗号分隔字符串
- 如何将整数值解析为逗号分隔字符串中的单独 int 变量?
- 如何分隔字符串并将每个部分存储在不同的向量中
- 如何按特定分隔符分隔字符串
- 逗号分隔字符串的总和,例如 O(n) 中的 4,1,3
- 如何使用符号分隔字符串而不是空格的输入字符串流
- C++中将不同类型的变量列表连接到逗号分隔字符串的最快方法是什么?
- C++ sscanf 空格分隔字符串
- 在C++中分隔字符串并存储到数组中的最佳方法
- 使用 find_first_of() 和 substr() 分隔字符串,但我得到的输出不正确
- 正在分析逗号分隔字符串中的整数
- 分析分隔字符串
- 用空格分隔字符串的最简单方法
- 分隔字符串的最佳ASCII字符是什么
- C++用空格和标点符号分隔字符串
- c#中分隔字符串中的数字和单位
- 如何基于标记分隔字符串
- c++使用wstring拆分unicode分隔字符串
- 如何在C++中用逗号分隔字符串