编译时出现代码错误
#include <stdio.h> // standard input / output functions
#include <stdlib.h>
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#include <termios.h>
void main()
{
int USB = open( "/dev/ttyUSB0", O_RDWR| O_NOCTTY );
struct termios tty;
struct termios tty_old;
memset (&tty, 0, sizeof tty);
/* Error Handling */
if ( tcgetattr ( USB, &tty ) != 0 )
{
printf("Error %d form tcgetattr : %d /n",&errno,strerror(errno));
}
}
错误是
USB2UART.c:18:49: error:lvalue required as unary ‘&’ operand
printf("Error %d form tcgetattr : %d /n",&errno,&strerror(errno));
^
我正在使用 USB 到 UART 的转换,并试图在其处理程序中出错。 希望有人能帮忙。谢谢:)
最佳答案
看起来您正在尝试将 &
应用于文字,而它应用于变量而不是文字。尝试删除 &
然后试一试。
C++ 标准,§5.3.1,3 说:
The result of the unary & operator is a pointer to its operand. The operand shall be an lvalue [...]
关于c++ - 需要作为一元 ‘&’ 操作数的 c 左值中的打印错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33073727/