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

what does int data:4 means

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







what does int data:4 means
PostPosted: Wed Jun 30, 2004 6:27 am     Reply with quote

int data define a integer, what 4 means, does 4 is the default value?
dyeatman



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

View user's profile Send private message

data:4
PostPosted: Wed Jun 30, 2004 7:10 am     Reply with quote

No, a default value is assigned with int data=4;

It is a bit width definition normally used in a struct.

For more information see page 64 of the CCS C manual where it is shown.
Ttelmah
Guest







Re: what does int data:4 means
PostPosted: Wed Jun 30, 2004 10:12 am     Reply with quote

guest wrote:
int data define a integer, what 4 means, does 4 is the default value?

This is the standard C declaration for a '4bit' value. You can store sizes smaller than an integer 'inside' an integer, using the ':' to specify the number of bits required. This can be very useful to access multiple 'parts' of a register for instance, so if you declare a structure, with:
struct fred {
int8 address:4;
int8 goflag:1;
int8 error:2;
int8 marker:1;
} register;

and then 'locate' it to a particular memory spot, you can access the first four bits of the byte at that point, using:
register.address

and the next bit in the same byte as:
register.goflag

This is a very useful way of talking to 'parts' of a byte.
On it's own, the declaration means that 'data' is now a 4bit number, able to hold 0..15 only.

Best Wishes
Guest








PostPosted: Wed Jun 30, 2004 10:58 am     Reply with quote

Thank you both of you:

I raised this question because I found a definition like this in lcd.c

struct lcd_pin_map {
Boolean enable;
Boolean ers;
Boolean ws;
Boolean unused;
int data: 4;
} lcd;


struct lcd_pin_map const LCD_READ={0,0,0,0,15};
set_tris_lcd(LCD_READ); //set_tris_lcd(LCD_READ) equals set_tris_b(LCD_READ)

and set_tris_b(value); hocome the struct become value define in set_tris_b(value)

so right now the LCD_READ=00001111, right?
Ttelmah
Guest







PostPosted: Wed Jun 30, 2004 2:26 pm     Reply with quote

Yes. :-)
Jeprox
Guest







PostPosted: Wed Jun 30, 2004 4:34 pm     Reply with quote

In C, check out the topic on Bit Field.
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