View previous topic :: View next topic |
Author |
Message |
Marco27293
Joined: 09 May 2020 Posts: 126
|
Bit shift on a constant ROM variable |
Posted: Thu May 21, 2020 6:05 am |
|
|
Hi all,
I'm working with a PIC18F46J50 using a PCH v5.090 CCS Compiler.
I defined a variable in the ROM :
Code: | const int32 Mic_active_hour = 1; |
In main program I perform a bit shift operation using the above defined variable:
Code: | int32 support = ((Mic_active_hour)<<5)); |
This assignment correctly give a value of 32 to support variable, or using 'const' something goes wrong? |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Thu May 21, 2020 6:18 am |
|
|
If you want it to be a ROM constant then why not just use
#define (int32)1
In the example you show this would then be done at compile time instead of run time. |
|
|
Marco27293
Joined: 09 May 2020 Posts: 126
|
|
Posted: Thu May 21, 2020 6:25 am |
|
|
Support variable value is 32 ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu May 21, 2020 6:29 am |
|
|
It'd need a name, but you are dead right. #define is potentially more
efficient.
#define Mic_active_hour (int32)1
I use hundreds of declarations like this shifted and combined for
graphic configuration stuff.
I'd suspect the optimiser will actually be treating it the same way anyway.
Over the years, the optimiser in CCS, has got better and better at doing this
sort of thing. I'm sure it will actually not be using any storage at all
for Mic_active_hour, and will be pre-solving the shift to store
32 in 'support'.
As posted the 'support; declaration has one too many brackets on
the right. |
|
|
|