Hello
I need to understand what the following line does:
What does the syntax "1 << SOMEVALUE" do?Code:.end = 0x20000000 + (1 << MAX(VAL1,VAL2)))
Thank you.
Printable View
Hello
I need to understand what the following line does:
What does the syntax "1 << SOMEVALUE" do?Code:.end = 0x20000000 + (1 << MAX(VAL1,VAL2)))
Thank you.
So, with MYVALUE1=1 and MYVALUE2=2...
MYCONST1 now contains 2, and MYCONST2 contains 4.Code:#defined MYCONST1 (1<<MYVALUE1)
#defined MYCONST2 (1<<MYVALUE2)
Thanks for the link.
Yes...
Although technically, there is no MYCONST1 or MYCONST2. What you did was define a macro named MYCONST1, which will be replaced by the text "(1<<MYVALUE1)" wherever it is encountered.
You should do this instead:
This has many advantages:Code:const int MYCONST1 (1<<MYVALUE1)
const int MYCONST2 (1<<MYVALUE2)
- Avoids errors due to collision: If someone else elsewhere has a "MYCONST1", you will receive a diagnostic
- Makes debugging easier: You'll have an actual symbol named MYCONST1.
- Tighter type safety: MYCONST1 has a pre-defined type. Any conversion that might lose information will give a diagnostic.
monarch_dodra was a bit quick there with the copy, paste & edit... ;)
Code:const int MYCONST1 = (1<<MYVALUE1);
const int MYCONST2 = (1<<MYVALUE2);