问题描述
我已经问过一个类似的问题,但我知道我可以' ŧ使磁头或赘言和templateness的尾巴。我是一个C(而不是C ++)程序员。
I have asked a similar question before, but I realize that I can't make heads or tails of the macrology and templateness. I'm a C (rather than C++) programmer.
什么是F()实际上呢?当它的东西字符转换成pgmem?当它拉出来的字符的pgmem?是否缓存它们?它是怎样处理的低内存情况?
What does F() actually do? When does it stuff characters into pgmem? When does it pull characters out of pgmem? Does it cache them? How does it handle low-memory situations?
推荐答案
有没有涉及模板,只有函数重载。在 F()
宏做了两件事:
There are no templates involved, only function overloading. The F()
macro does two things:
-
使用
PSTR
来确保文字字符串存储在Flash存储器(code空间而非数据空间)。然而,PSTR(一些字符串)
无法打印,因为这样会得到一个简单的的char *
这再次presents存储在闪存字符串的基址。解引用该指针将在数据同一地址访问某些随机字符。这就是为什么F()
也...
uses
PSTR
to ensure that the literal string is stored in Flash memory (the code space rather than the data space). However,PSTR("some string")
cannot be printed because it would receive a simplechar *
which represents a base address of the string stored in Flash. Dereferencing that pointer would access some random characters from the same address in data. Which is whyF()
also...
蒙上的结果PSTR()
到 __ FlashStringHelper *
。功能,如打印
和的println
超载,这样,在接收到 __ FlashStringHelper *
的说法,他们正确地取消引用在闪存中的字符。
casts the result of PSTR()
to __FlashStringHelper*
. Functions such as print
and println
are overloaded so that, on receiving a __FlashStringHelper*
argument, they correctly dereference the characters in the Flash memory.
这篇关于Arduino的F():这是什么实际上做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!