|
|
View previous topic :: View next topic |
Author |
Message |
butterfly
Joined: 04 Jun 2006 Posts: 35
|
how to create global const in program |
Posted: Wed Sep 06, 2006 6:58 am |
|
|
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
|
|
Posted: Wed Sep 06, 2006 7:11 am |
|
|
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
|
|
Posted: Wed Sep 06, 2006 7:17 am |
|
|
thanks
how can i create a global various then |
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 06, 2006 7:28 am |
|
|
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 |
|
|
|
|
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
|