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 support@ccsinfo.com

Data Types

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



Joined: 01 Apr 2006
Posts: 3

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

Data Types
PostPosted: Sun Apr 02, 2006 2:29 pm     Reply with quote

Hello!

I was wondering which the limits were for a variable depending on its type. I looked in CCS help but I only found this:

int1
Defines a 1 bit number
int8
Defines an 8 bit number
int16
Defines a 16 bit number
int32
Defines a 32 bit number
char
Defines a 8 bit character
float
Defines a 32 bit floating point number
short
By default the same as int1
Int
By default the same as int8
long
By default the same as int16
void
Indicates no specific type

I was looking for the range that these types have; for example, int8 goes from 0 to 255.

I was told to read the file float.h but I only got some facts and I got confused Smile

Please tell me where to find a table that includes this info.

Thanks in advance! Wink
Ttelmah
Guest







PostPosted: Sun Apr 02, 2006 2:40 pm     Reply with quote

Use a calculator.
The size of number that an integer format can hold, is 2^n, where 'n' is the number of bits used to hold the value. So an int16, can hold 2^16 = 65536 values. You have to include '0', so the values can be 0 to 65535.
For 'signed' numbers, one bit is used to hold the sign, so a 'signed int8', can only hold 2^7 positive values.
The definition you give for 'void', is the one for C++ (where a void can be used to return any numeric type, and then converted to the required form). In CCS C, void specifically means 'no return'.
In a 'float', you have what is effectively a 24bit integer (only 23 bits are actually stored), which is then scaled by the exponent. The values in float.h, give the ranges for this. Basically you get slightly over 6 decimal digits of accuracy, scaled to cover numbers from 'FLT_MIN', up to 'FLT_MAX'.

Best Wishes
dyeatman



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

View user's profile Send private message

PostPosted: Sun Apr 02, 2006 2:43 pm     Reply with quote

If you are unable to count in binary you may be in for some serious problems trying to write programs...but here goes...

Basically the number of bits tells you the range:

8 bits allows you to count in binary 0-255
16 bits = 65535
32 bits - 4,294,967,295

This is for unsigned vars.

For signed variables the range is 1/2 the above and the MSB (most significant bit) is used as the sign bit to allow +/-.

Example: SIGNED 16 bit vars can hold from +32,767 down to -32,768

Here is a link to explain the ANSI C data types/byte sizes:
http://www.phim.unibe.ch/comp_doc/c_manual/C/CONCEPT/data_types.html

Keep in mind the CCS variable sizes are different than standard ANSI C as you listed earlier so you have to translate (e.g. INT in CCS is 8 bits but is 16 bits in ANSI C).

Good Luck!

EDIT: Sorry TTelmah, it seems I came I right after you did...
migsantiago



Joined: 01 Apr 2006
Posts: 3

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

PostPosted: Sun Apr 02, 2006 9:34 pm     Reply with quote

Thank you guys, I also had some questions about the signs (+/-) but now they're solved. Very Happy
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