Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC 4.2.2 unsigned short error in casting

this line of code isn't compiling for me on GCC 4.2.2

m_Pout->m_R[i][j] = MIN(MAX(unsigned short(m_Pin->m_R[i][j]), 0), ((1 << 15) - 1));

error: expected primary-expression before ‘unsigned’

however if I add braces to (unsigned short) it works fine.

can you please explain what type of casting (allocation) is being done here?

why isn't the lexical parser/compiler is able to understand this c++ code in GCC?

Can you suggest a "better" way to write this code? supporting GCC 4.2.2 (no c++11, and cross platform)

like image 314
Gilad Avatar asked Nov 23 '25 10:11

Gilad


1 Answers

  1. unsigned short(m_Pin->m_R[i][j]) is a declaration with initialisation of an anonymous temporary, and that cannot be part of an expression.

  2. (unsigned short)(m_Pin->m_R[i][j]) is a cast, and is an expression.

So (1) cannot be used as an argument for MAX, but (2) can be.

like image 168
Bathsheba Avatar answered Nov 25 '25 01:11

Bathsheba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!