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

URGENT: strtol and pointers problems

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



Joined: 29 Sep 2005
Posts: 7

View user's profile Send private message MSN Messenger

URGENT: strtol and pointers problems
PostPosted: Wed Nov 23, 2005 2:40 pm     Reply with quote

Hi all!
In a program for my diploma project I want use the strtol function which extract a long from a string. Regarding to CCS Compiler reference manual the following code should give result = 123 and ptr = "hello"
Code:
signed long result;
char str[2]="123hello";
char *ptr;
result=strtol(str,&ptr,10);


Two questions about this example:
1. str is declared to be 2 of length should it not be 9 for avoiding overwrite?
2. This example works well if str is stored in lower adresses (<255). If str is stored for example at adress 0x100 ptr should be 0x0103 but is 0x0003 in reality as if only lower byte was copied... Is this a problem of 8 bit or 16 bit pointers? Should a char **ptr (double indirection) be used as in standard C strtol?
I'm using a PIC18F452 with #device *=16 directive and CCS 3.239.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 3:22 pm     Reply with quote

I made a test program based on your post and I did see a problem.
Maybe you should report this to CCS.

As a work-around, you can use the adtol() function
("ASCII decimal to long") shown in the following thread.
Or you can modify it as needed.
http://www.ccsinfo.com/forum/viewtopic.php?t=17563&highlight=adtol
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