[英]What does this operator do?
我正在为中文arduino编写Linux驱动程序。 有一瞬间,我需要更改波特率。 我查找了示例,发现清单:
Listing 2 - Setting the baud rate.
struct termios options;
/*
* Get the current options for the port...
*/
tcgetattr(fd, &options);
/*
* Set the baud rates to 19200...
*/
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
/*
* Enable the receiver and set local mode...
*/
options.c_cflag |= (CLOCAL | CREAD);
/*
* Set the new options for the port...
*/
tcsetattr(fd, TCSANOW, &options);
代码的最后一行具有|=
运算符。 它有什么作用? 我从没看过
options.c_cflag |= (CLOCAL | CREAD);
通常相当于
options.c_cflag = options.c_cflag | (CLOCAL | CREAD);
除了options.c_cflag
只被评估一次,在上面的表达式中没关系,但是options.c_cflag
是否有副作用(例如,如果它是*options.c_cflag++
)则很重要*options.c_cflag++
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.