The use of ": ?“ in" _rxBuffer, rxSpace ? : _default_rx_buffer_size"

Any help will be very appreciated.

This is the code related:

……
if (!_allocBuffer(_rxBuffer, rxSpace ? : _default_rx_buffer_size)
|| !_allocBuffer(_txBuffer, txSpace ? : _default_tx_buffer_size))
{
end();
return; // couldn't allocate buffers - fatal
}
……

bool AVRUARTDriver::_allocBuffer(Buffer *buffer, uint16_t size)
{
……
}

The code is compiled in Arduino IDE successfully,but not in Vistual Studio.Why?
Can this "? :" used in Arduino?

Can this "? :" used in Arduino?

Yes, it's the ternary operator.

The code is compiled in Arduino IDE successfully,but not in Vistual Studio.Why?

Let me ask another question. Why didn't you post the error messages?

We've hired a psychic, but his start data is the 12th of Never. If you need help before then, you need to at least make it possible to help you.

所谓三目运算符当然应该有三个操作数,我的问题是为什么上文代码中的”?“后面没有操作数也能在arduino编译成功,只是想问一个问题,可能比较简单,不喜勿喷!Understand?Thank you!

[Google translation: The so-called three head operator should certainly have three operands, my question is why the above code "?" Is not followed by the operands can be successfully compiled arduino, just want to ask a question, may be relatively simple, do not like do not spray !

  • Moderator]

Understand?

No.

Thank you!

You're quite welcome.

My next guess is because the identifiers (e.g., _rxBuffer, rxSpace , _default_rx_buffer_size) are defined for the Arduino IDE but not Visual Studio.

The compiler returns this on testing:

sketch_may11a.ino:11:19: warning: ISO C++ does not allow ?: with omitted middle operand [-Wpedantic]
sketch_may11a.ino:11:21: warning: ISO C++ forbids omitting the middle term of a ?: expression [-Wpedantic]

Which is a clear indication of a GCC extension. On searching the warning in Google I found an article, and indeed its specific to the GNU compiler:

You may be able to find info on google whether visual studio has support for this feature.

Got it.
I have tried the "A? :B" in Visual Studio.It can't be complied.
Thank you very much for your concern of my question!