|
|
View previous topic :: View next topic |
Author |
Message |
object01
Joined: 13 May 2004 Posts: 90 Location: Nashville, TN
|
Global/local use of enum |
Posted: Tue Sep 28, 2004 9:59 am |
|
|
Why doesn't this work in CCS...
Code: | #include <18F2320.h>
enum Colors {red, green, blue};
void main() {
enum Colors c;
} |
But this does?
Code: | #include <18F2320.h>
void main() {
enum Colors {red, green, blue};
enum Colors c;
} |
--
Jeff S. |
|
|
Guest
|
Re: Global/local use of enum |
Posted: Tue Sep 28, 2004 10:56 am |
|
|
object01 wrote: | Why doesn't this work in CCS...
Code: | #include <18F2320.h>
enum Colors {red, green, blue};
void main() {
enum Colors c;
} |
But this does?
Code: | #include <18F2320.h>
void main() {
enum Colors {red, green, blue};
enum Colors c;
} |
--
Jeff S. |
I'd suspect the keyword, is 'scope'. The identifier, must be 'in scope' for the declaration to work. Traditionally, an object declared outside a routine, is 'global', and 'in-scope', for the whole program. CCS handles this for variable names (a variable called 'fred' declared outside the routines, is given the label 'fred', while a variable called 'fred', declared inside main, is given the label 'main.fred', and the search rules try looking for this definition first, then move 'out' to the one outside), but it would appear, does not do this, for the enum definition, and will only find the one that is in the same area.....
The defintion _should_ follow the standard scope rules, so this is a definate 'error'.
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
|