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

byte?

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

byte?
PostPosted: Tue Oct 23, 2012 12:32 am     Reply with quote

what is the difference between declaring:
int8 var_name
and
byte var_name
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 1:29 am     Reply with quote

Nothing.
Just other names.
In fact if you look in the include file for the processor, you will find the line:

#define BYTE int8

int = int8 = char = byte
on the PIC18/16.

Danger is though that if you switch to a PIC24, int is no longer in this list.

This is why in general it is 'better' practice to use:

intn sizes (like int8, int16, int32) for numeric values.

Then use 'char' for alphabetic text, and (possibly) use 'byte' for things that are being sent over 'byte wide' transport media (RS232 etc.).

This way you are confident about the sizes, and 'know' they are suitable for what is being done with them.....


Best Wishes
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 10:14 am     Reply with quote

Thx a lot but what happens with int at pic24? As I understand it is no longer int8.
ckielstra



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

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 11:47 am     Reply with quote

Sigh.... what is the part you didn't understand?
Yes, that is what Ttelmah wrote:
Quote:
#define BYTE int8

int = int8 = char = byte
on the PIC18/16.

Danger is though that if you switch to a PIC24, int is no longer in this list.

And that is the same reason why he wrote:
Quote:
it is 'better' practice to use:

int sizes (like int8, int16, int32) for numeric values.

So, when you write everywhere in your program int8 or int16 instead of just 'int', then then it doesn't matter when you change to another compiler where the size of 'int' is 8, 16 or 32 bits.

For the exact size and definitions of all the compiler defined types have a look in the PCD Reference Manual, chapter "Data definitions".
Battery David



Joined: 01 Feb 2010
Posts: 25

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 12:24 pm     Reply with quote

I was poked in the ribs by a "real" programmer once to get me to be explicit on every variable type. Since an 'int' could be different on different parts, I now always do full declarations:

Code:

unsigned int8 Dog;
signed int16 Fish;
unsigned int1 ControlBit;
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Oct 23, 2012 12:36 pm     Reply with quote

Because of my ugly roots in ASM land - I second batterydavids reply.
I have ALWAYS explicitly declared my integer Vars as signed or unsigned
( except for int 1 ;-))

and it is a good way to keep your thoughts and your program clear.
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 2:54 pm     Reply with quote

It's also worth noting that for PIC24 at least, that set of equalities isn't always true. Some versions of the compiler in the late 120s or early 130's default char to signed and int8s to unsigned, which can snag you sometimes. I haven't checked to see if that is still the case
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