I am writing a Linux driver for my chinese arduino. At one moment I need to change the baud rate. I looked for examples and found that listing:
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);
The next to last line of code has the |=
operator. What does it do? I've never seen it before.
a |= b;
->a = a | b;
(with the difference being thata
is evaluated only once with the|=
operator, thanks Filipe!) – Kninnug Oct 22 '15 at 22:18|=
is compound bit-wiseinclusive OR
assignment operator. – haccks Oct 22 '15 at 22:19a |= b
is equivalent toa = a | b
with the exception thata
is only evaluated once. This is important if the expressiona
has side effects. – Filipe Gonçalves Oct 22 '15 at 22:21