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

int declaration is 8 bits, any way to make it 16 bits???

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



Joined: 09 May 2007
Posts: 1

View user's profile Send private message

int declaration is 8 bits, any way to make it 16 bits???
PostPosted: Wed May 09, 2007 6:18 am     Reply with quote

This might be a newbie question.

When I define an int variable, the compiler always makes it 8 bits instead of the normal 16 bits. Is there any way to make the compiler define int as a standard 16 bit integer, or do I always have to declare variables as int16 ??? This is a pain when converting existing programs.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed May 09, 2007 6:28 am     Reply with quote

Yes, changing is possible. Check the #type directive in the CCS manual.
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: int declaration is 8 bits, any way to make it 16 bits???
PostPosted: Wed May 09, 2007 1:32 pm     Reply with quote

leeccs wrote:

When I define an int variable, the compiler always makes it 8 bits instead of the normal 16 bits.

on a PIC, "normal" is 8 bits -- it is, after all, an 8 bit microcontroller. so, it is incorrect to assert that the compiler is doing something to make an int 8 bits wide, instead of 16. 8 bits wide is the natural state, 16 bits wide and greater requires work -- not the other way around.

leeccs wrote:

Is there any way to make the compiler define int as a standard 16 bit integer, or do I always have to declare variables as int16 ??? This is a pain when converting existing programs.


personally, i would never change the global int definition from 8 to 16bits.

number 1, you are asking for trouble, and will eventually run into some hard to find problem either in your own application code, your imported application code, the compiler libraries, or a device driver.

number 2, you are unnecessarily doubling the RAM usage.

number 3, almost everything you do on a PIC in terms of I/O is done with 8 bit values -- serial rs232, i2c, dallas onewire, SPI, and so on. you are going to cause yourself much grief when needlessly using 16 bit values.

my suggestion -- open your imported code in a suitable text editor, and use stepwise search and replace -- selectively changing the int's into int16's. then, pull that into your application codebase.

jds-pic
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed May 09, 2007 2:49 pm     Reply with quote

I fully agree with JDS-PIC in his reply.

However, to be fair and answer your question:

Yes, you can change the default. In the latest manual, see pages 23 (Basic and Special Types) and the #Type pre-processor command on page 103.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: int declaration is 8 bits, any way to make it 16 bits???
PostPosted: Wed May 09, 2007 4:00 pm     Reply with quote

leeccs wrote:
This might be a newbie question.

When I define an int variable, the compiler always makes it 8 bits instead of the normal 16 bits. Is there any way to make the compiler define int as a standard 16 bit integer, or do I always have to declare variables as int16 ??? This is a pain when converting existing programs.


Remember that integer literally means its not a floating point number. I would say it falls under best practices to declare every variable used with embedded code explicitly. On a PC it's a lot looser.

Int1
Int8
Int16
Int32
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