CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Bit shift on a constant ROM variable

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Marco27293



Joined: 09 May 2020
Posts: 126

View user's profile Send private message

Bit shift on a constant ROM variable
PostPosted: Thu May 21, 2020 6:05 am     Reply with quote

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: 296

View user's profile Send private message

PostPosted: Thu May 21, 2020 6:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 21, 2020 6:25 am     Reply with quote

Support variable value is 32 ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Thu May 21, 2020 6:29 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group