Jump to content

According to this C++ reference + and - are right-to-left associative and have the same precendence:

http://en.cppreference.com/w/cpp/language/operator_precedence

 

So you would read it as:

x = (r + (t - (g + f)))

 

This will lead to something like this:

add $s5 $s3 $s4

substract $s5 $s2 $s5

add $s0 $s0 $s5

 

The exact operations and op codes are dependent on the specific Instruction Set Architecture you're compiling too.

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
https://linustechtips.com/topic/470103-solve-a-problem/#findComment-6310116
Share on other sites

Link to post
Share on other sites

According to this C++ reference + and - are right-to-left associative and have the same precendence:

http://en.cppreference.com/w/cpp/language/operator_precedence

 

So you would read it as:

x = (r + (t - (g + f)))

 

This is incorrect. It looks like you confused the binary operators with the unary operators.

 

C++ follows proper order of operations for arithmetic. The table in your link also shows that addition and subtraction are "Left-to-right" associative which is the opposite of what you wrote.

x = (((r + t) - g) + f) // brackets are of course unnecessary and are just included for comparison to the quoted answer
Link to comment
https://linustechtips.com/topic/470103-solve-a-problem/#findComment-6311001
Share on other sites

Link to post
Share on other sites

 

This is incorrect. It looks like you confused the binary operators with the unary operators.

 

C++ follows proper order of operations for arithmetic. The table in your link also shows that addition and subtraction are "Left-to-right" associative which is the opposite of what you wrote.

x = (((r + t) - g) + f) // brackets are of course unnecessary and are just included for comparison to the quoted answer

My bad i mixed up the different +/- symbols.

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
https://linustechtips.com/topic/470103-solve-a-problem/#findComment-6314757
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×