|
|
View previous topic :: View next topic |
Author |
Message |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Feb 25, 2010 4:14 am |
|
|
But this thread is about the line:-
#define test 0x42
Either, the poster doesn't know much about C so describing the ins and outs of lvalues and const's isn't going to help or John P post is correct and the poster has been told a joke which they do not understand.
Based on the original post I would say all this stuff about const is off topic.
The last you will hear from me on the subject, in this thread anyway |
|
|
Gavin Pinto
Joined: 18 Oct 2009 Posts: 27 Location: Australia
|
|
Posted: Thu Feb 25, 2010 4:30 am |
|
|
Wayne_ wrote: | But this thread is about the line:-
#define test 0x42
Either, the poster doesn't know much about C so describing the ins and outs of lvalues and const's isn't going to help or John P post is correct and the poster has been told a joke which they do not understand.
Based on the original post I would say all this stuff about const is off topic.
The last you will hear from me on the subject, in this thread anyway |
Anyway I give more information below to those who wish to read.
WARNING: Preprocessor macros, although tempting, can produce quite unexpected results if not done right. Always keep in mind that macros are textual substitutions done to your source code before anything is compiled. The compiler does not know anything about the macros and never gets to see them. This can produce obscure errors, amongst other negative effects. Prefer to use language features, if there are equivalent (In example use const int or enum instead of #defined constants).
http://en.wikibooks.org/wiki/C_Programming/Preprocessor
https://www.securecoding.cert.org/confluence/display/seccode/DCL06-C.+Use+meaningful+symbolic+constants+to+represent+literal+values _________________ Clear Logic |
|
|
Gavin Pinto
Joined: 18 Oct 2009 Posts: 27 Location: Australia
|
|
Posted: Tue Mar 02, 2010 4:41 pm |
|
|
You might look at this ccs thread and ask many questions
https://www.ccsinfo.com/forum/viewtopic.php?t=23400
Now I will show some interesting enum statements that compile with ccs.
1. enum{u,v,w};
2. enum {a,b,c} *ep;
3. enum ee{x,y,x}*ez;
4. enum xy{i,j,k}uv;
5.enum {a=0xFFFFFFFF};
6.enum{a=0xFFFFFFFF}ep;
7.enum{a=4294967298}ep; // Compiles in #device ANSI mode (signed)why ?????
8. enum{a=0b11111111111111111111111111111111}ep; //Compiles in #device ANSI mode (signed) why?????
9.enum{a=-2147483649}ep;//Compiles in #device ANSI mode (signed) why?????
10. enum{a=-214748364987654321}ep;//Compiles in #device ANSI mode (signed) why?????
Those that do not compile
1. enum {a=0xFFFFFFFF}*ep;
*** Error 84 : Pointers to bits are not permitted
2.enum{a=0x100000000}ep;
***Error 103 : Constant out of the valid range
enum{a=O40000000000}ep; //Octal representation
***Error 103 : Constant out of the valid range
CCS compiler version 4.104 PCH command-line. Processor PIC18F8722
Any questions or discussions on the above statements?
C Enumeration Declarations
http://msdn.microsoft.com/en-us/library/whbyts4t.aspx _________________ Clear Logic |
|
|
|
|
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
|