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 CCS Technical Support

how to create global const in program

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



Joined: 04 Jun 2006
Posts: 35

View user's profile Send private message

how to create global const in program
PostPosted: Wed Sep 06, 2006 6:58 am     Reply with quote

normaly to create global const ;

const int16 MASK = 0x0000;

i want to read eeprom adm create global const like that
main(){
const int16 MASK = read_EEPROM (0x00);

}

and give this error:

*** Error 51 "C:\umut\um\alt1.c" Line 68(1,6): A numeric expression must appear here

how to make it happen?
Ttelmah
Guest







PostPosted: Wed Sep 06, 2006 7:11 am     Reply with quote

What you describe, is impossible.
Simply declare a normal global variable, and read the EEPROM data into it. A_constant_ is 'read only', so, you cannot write data into it.
You can declare a variable that lives in EEPROM, using the typemod directive.
Your expression fails for two reasons. The first is the inability to write to a constant, while the second is that 'read_eeprom', is a function, only returning a value when it is run, while the constant declaration, occurs at compile time, so no value is available.

Best Wishes
butterfly



Joined: 04 Jun 2006
Posts: 35

View user's profile Send private message

PostPosted: Wed Sep 06, 2006 7:17 am     Reply with quote

thanks

how can i create a global various then
Ttelmah
Guest







PostPosted: Wed Sep 06, 2006 7:28 am     Reply with quote

Any variable declared outside the subroutines, is 'global'. Declare a variable at the head of the program, and it is available to all the routines.
Code:

int16 value=0;

void demosub(void) {
   printf("%4ld/n",value);
}

void main(void) {
   demosub();
   value=10;
   demosub();
   while (TRUE) ;
}


This will print '0', and then '10', with 'value' being accessable inside both routines.

Best Wishes
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