我为 i2c 创建了一个头文件,来自 Peter Fleury。我在 Eclipse 中重写并在下面的列表程序的第二行中收到错误警告“此行有多个标记 - 语法错误 - 预期标识符或 '(' 在 'unsigned' 之前”
>#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak();
>
>unsigned char i2c_read (unsigned char ack);
有人可以帮助我吗?
What are you trying to achieve? If you preprocess the #define macro you'll get:
unsigned char (unsigned char ack) ? i2c_readAck() : i2c_readNak();;
This isn't a legal C. I'm not familiar with i2c, and I don't know what you are trying to do. If you are trying to declare a new variable and initialize it with a value (and call the correct method), you should:
#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak()
unsigned char new_var = i2c_read (ack);
Note that I'm assuming ack is defined somewhere else. If you are trying to achieve something else, please specify it in your question. Also note I removed one semicolon from the '#define'. It is a common mistake, which typically only generate a warning or go unnoticed.
Oh, and if you are trying the declare a function, then it should have a different name than the macro.
You have defined a macro and declared a function with same name.
Perhaps you should change the macro name or function name.