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

access to a bit

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



Joined: 19 Dec 2014
Posts: 16

View user's profile Send private message

access to a bit
PostPosted: Mon Jan 23, 2017 2:08 am     Reply with quote

Hi,
I have a question please,

I declared:
#bit TRMT=TX1STA.1

if I want to create another variable - NEW_VAR that I can access to TRMT value so:
if (TRMT)
and
if (NEW_VAR)
will be the same..

is this possible?

is
int1 NEW_VAR=TRMT; ,is good?
#define NEW_VAR TRMT ,is good?

#bit NEW_VAR=TRMT not compile..

thank you
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Jan 23, 2017 2:56 am     Reply with quote

Code:

#define NEW_VAR TRMT


Is the way to do it... but it is not a "new variable", it is simply the same TRMT with another name.

However, I do not see any reason why this might be a good idea, and it is pretty much certainly not necessary. It is rarely better to have two or more names for the same thing: it just creates confusion. What is wrong with TRMT? Especially when it is the MIcrochips's name for a peripheral control bit?
id31



Joined: 19 Dec 2014
Posts: 16

View user's profile Send private message

PostPosted: Mon Jan 23, 2017 3:02 am     Reply with quote

OK, got it! Smile thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19445

View user's profile Send private message

PostPosted: Mon Jan 23, 2017 3:08 am     Reply with quote

This:
int1 NEW_VAR=TRMT;

won't work.
It declares a new variable sitting somewhere else in memory, that is then loaded at the moment of declaration with the value in 'TRMT'.
Writing to NEW_VAR would write to it, not to TRMT. Reading NEW_VAR, would read it, and if TRMT has changed, the value would be out of date. Also wastes a bit of RAM to hold this.

This:
#define NEW_VAR TRMT

is perfectly fair. All #define does is create a text macro. So whenever 'NEW_VAR is typed in the code, it'll be replaced at compile time, with TRMT.

You can also just use:
#bit NEW_VAR=TXSTA.1

This creates another variable called 'NEW_VAR' that points to the same location in memory as TRMT.

Declaring an actual new variable will have the same effect in CCS. However in languages that implement more stringent type checking, it ensures that the compiler 'knows' the actual type of the variable involved, when performing syntax checking.
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