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

simple questions
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Feb 25, 2010 4:14 am     Reply with quote

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 Smile
Gavin Pinto



Joined: 18 Oct 2009
Posts: 27
Location: Australia

View user's profile Send private message

PostPosted: Thu Feb 25, 2010 4:30 am     Reply with quote

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 Smile


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

View user's profile Send private message

PostPosted: Tue Mar 02, 2010 4:41 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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