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

#DEVICE ANSI and program memory variables

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



Joined: 17 Nov 2016
Posts: 12

View user's profile Send private message Visit poster's website

#DEVICE ANSI and program memory variables
PostPosted: Sun Nov 27, 2016 5:49 pm     Reply with quote

I had to go over to ANSI mode with my CCS (PCH) compiler. This was because the default compiler uses case insensitive approach on object names.

After enabling the ANSI compiler I noticed that the "const" keyword no more meant "put this variable into program memory" but they were put into RAM instead. LOL - my puny PIC18F25K22 MCU did not have enough RAM ... Smile

The solution was to apply another pragma:
#DEVICE CONST=ROM

After this the "const" variables went to ROM.. Thank You Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 27, 2016 7:55 pm     Reply with quote

If you want to make the compiler case sensitive, you don't need ANSI.
Just use #case. It's in the manual.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Nov 28, 2016 1:46 am     Reply with quote

and the use of 'const' has also been covered many times before here.

CCS used the keyword 'const' to signify a variable held in ROM long before ANSI existed. When ANSI was designed, the same word was instead used to signify a RAM variable that was not changeable by the code. Now the PIC doesn't actually have the protections to do this, but the compiler will try to implement parts of this.
In fact #DEVICE CONST=ROM does not do quite the same as the old compiler. Quote from the readme that comes with the compilers:
Quote:

The CCS compilers traditionaly used the C keyword CONST to locate data in program memory.
ANSI uses this keyword to specify a read only data item. The version 4 compiler has a
new method of storing data in program memory for chips that allow program memory to be read.
These three storage modes may be set directly using one of the following qualifiers:
ROMI Traditional CCS method to store in ROM optimized for access from indexed arrays
ROM New method to save data in ROM optimized for when the user needs pointers to the data
_READONLY Marks the data item as read only, defaults to RAM (like ANSI wants)

By default the CONST keyword is the same as ROMI. The CONST behavior may be changed with
any of the following:
#device CONST=READ_ONLY
#device CONST=ROM
#device CONST=ROMI


So to give the same behaviour as you had without #DEVICE ANSI, you should actually use #device CONST=ROMI

Changing to ANSI also changes the default data type to 'signed'. Beware.

#device ANSI gives the following basic changes:

#device CONST=READ_ONLY
#type signed
#case
#device *=16 //You are probably running this anyway
esko



Joined: 17 Nov 2016
Posts: 12

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 29, 2016 5:34 pm     Reply with quote

Thanks for Your valuable time. It was well spent !

Added the 'I' to the pragma.

I am aware of the highest bit Smile

Actually I have been coding with C so long .... practically as long as there has been C compilers around - I even coded one myself for Hitachi's Motorola 6802 clone which did not have a decent compiler at early 80's - That compiler ran on a Motorola Exorset .... and the code was tested on Motorola MEK-6802-D5...

Edit: and as there were no C compilers around I coded the C compiler with assembler. Bought my first IBM XT 5 years later.... it had a BASIC interpreter Smile
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