Arduino 的“F()"是什么意思?其实呢? [英] What does Arduino's "F()" actually do?

查看:78
本文介绍了Arduino 的“F()"是什么意思?其实呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前问过一个类似的问题,但我意识到我可以'不要对宏观和模板性造成正面或反面.我是一名 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 (flash)?它什么时候从 pgmem 中提取字符?它会缓存它们吗?它如何处理内存不足的情况?

What does F() actually do? When does it stuff characters into pgmem (flash)? 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 来确保文字字符串存储在 闪存(代码空间而不是数据空间).但是,PSTR(some string") 无法打印,因为它会接收一个简单的 char *,它表示存储在闪存中的字符串的基地址.取消引用该指针将访问来自数据中相同地址的一些随机字符.这就是为什么 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 simple char * 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 why F() also...

PSTR() 的结果转换为 __FlashStringHelper*.printprintln 等函数被重载,因此在接收到 __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()"是什么意思?其实呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆