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

size of int, chars displaying big numbers!!

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



Joined: 18 Mar 2005
Posts: 8

View user's profile Send private message

size of int, chars displaying big numbers!!
PostPosted: Fri May 13, 2005 7:13 am     Reply with quote

Hi there I`ve got another problem:

I`m using PIC 18f6720 and the newest CCS C Compiler (finally)!

Where should I start?

1. Is there a difference between an interger and a char?
when I use the sizeof() function and print it on screen it will always say 1 Byte!

2. When I try to search the maximum of the number, an integer can display it s always 127, it doesn t matter if it s signed or unsigned...

3. When I use the function of malloc(), It will allocate memory till 199 Bytes I think so...
I have tried with this structure:


Code:

struct message_Handler
{
   int type;
   int value;
   int status;
   char text[196];
   struct message_Handler* next;
};


I have raised the number of the array and when I insert a number over 196 the programm will crash!!
I know the manual says when I try to allocate more than a integer can represent as a number it won t go!
Is my struct about the limit of an integer???

But why these different numbers???

plz help me guys I don t understand these irregularities!
_________________
Why I get all these strange problems ?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri May 13, 2005 8:20 am     Reply with quote

Quote:

1. Is there a difference between an interger and a char?
when I use the sizeof() function and print it on screen it will always say 1 Byte!


Integer size depends of the implantation. In CCS int, int8, byte and char are 8 bit integers.
See Data Types in Page 81 pdf CCS Manual.


Quote:

2. When I try to search the maximum of the number, an integer can display it s always 127, it doesn t matter if it s signed or unsigned...


??? Tell us where/how do you search that.

Quote:

3. When I use the function of malloc(), It will allocate memory till 199 Bytes I think so...


#device *=16 is the trick.
Read this topic regarding allocating variables and RAM banks in Page 247

Best wishes,

Humberto
Ttelmah
Guest







PostPosted: Fri May 13, 2005 10:04 am     Reply with quote

I suspect the '127', probably comes from using printf, with the wrong conversion. If he is printing the numbers with %d, the maximum that can be printed from a value, will be 127, since this is the print conversion for a signed integer. If instead he uses %u, the value allowed will go up to 255.

Best Wishes
Guest








PostPosted: Tue May 17, 2005 5:24 am     Reply with quote

Thnx Humberto and Ttelman.
1. Is ok. How couldn t see this topic in the manual??
2. It s like Ttelman said i tried to print thenumbers and used %d

@ 3. U mean to read the example programs? The page is about them...

I suspect u mean #define a numeber and use them in the malloc function except the function sizeof() !??!

Thnx again! Razz
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