这个操作员是做什么的?

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);

except options.c_cflag 只计算一次,这在上面的表达式中无关紧要,但如果 options.c_cflag 有任何副作用(例如,如果它是 *options.c_cflag++)