[英]what does the * mean in c
This is a C language question. 这是一个C语言问题。
Does the * mean multiply or something else in function below? *表示乘或以下函数中的其他内容吗? The reason I ask is because the function definition comments says it expects three params. 我问的原因是因为函数定义注释说它期望三个参数。 Also do the ()
[parenthesis] in the #defines
mean something different from no parenthesis? #defines
的()
[括号]是否也不同于没有括号的含义? See below. 见下文。
The function call: 函数调用:
nvm_eeprom_write_byte(TEST_ERASE_PAGE * EEPROM_PAGE_SIZE, 42);
The definitions: 定义:
#define TEST_ERASE_PAGE 2
#define EEPROM_PAGE_SIZE 32
Comments for the function definition: 函数定义的注释:
The function definition: 函数定义:
void nvm_eeprom_write_byte(eeprom_addr_t address, uint8_t value) {}
eeprom_addr_t
is a typedef: eeprom_addr_t
是一个typedef:
typedef uint16_t eeprom_addr_t
#define EEPROM_START (0x0000)
#define EEPROM_SIZE (2048)
#define EEPROM_PAGE_SIZE (32)
#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
Yes, it just means multiply in this context. 是的,这仅意味着在这种情况下相乘。 It's multiplying two #defined constant to make the first argument to the nvm_eeprom_write_byte
function. 它将两个#defined常数相乘以成为nvm_eeprom_write_byte
函数的第一个参数。
This code involves a lot of assumptions about memory address manipulation. 此代码包含有关内存地址操作的许多假设。 Gotta be honest with you, if you don't know C, looking at EEPROM driver code probably isn't the simplest or safest way to start. 老实说,如果您不懂C,查看EEPROM驱动程序代码可能不是最简单或最安全的启动方法。
Yes, *
means multiply
in C. 是的, *
表示multiply
C。
Parenthesis in #define
is a standard practice in C to prevent unexpected results when using compound statements (where operator precedence matters). #define
中的括号是C中的一种标准惯例,可以防止在使用复合语句(运算符优先级很重要)时出现意外结果。
Consider the difference between 考虑一下之间的区别
#define FOO 1+2
int a = FOO*2
and 和
#define FOO (1+2)
int a = FOO*2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.