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

Problem in itoa while it's used in multiple unit

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



Joined: 17 Jan 2015
Posts: 8
Location: 美国

View user's profile Send private message AIM Address

Problem in itoa while it's used in multiple unit
PostPosted: Sat Feb 03, 2018 5:33 am     Reply with quote

I get trouble in using itoa in multiple compile unit.
Here's my code:

Code:

#include "18F46K22.H"
#include "stdlib.h"

void main(){
    char buf[] = "0123456";
    itoa(1, 10, buf);
}


In another c file, stdlib.h is also included for other purpose.

The expected result of executing itoa would be the content of buf is changed to "1", however, it's not.

The actual result is "0". After debug i found that buf[0] remains unchanged and buf[1] was set to 0.

I tried many ways to work it around, finally i found remove stdlib.h from the other compile unit makes itoa works as expected.

I checked the source code of stdlib.h, and found it provides the implementation of itoa() instead of a declaration, I guess this is probably the root-cause. But how do I address the issue as I have to use stdlib.h in multiple compile units.
The only work-around i can think now is to provide a new version of stdlib.h and move the implementation code to a C file.

Is there any other solution? Or did anybody meet the same or similar issue?

By the way, the issue was initially found in 5.025, but I tried 5.049 and 5.075 the behaviors are same.
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Sat Feb 03, 2018 12:57 pm     Reply with quote

You just have to #EXPORT it in the file where you load it, and #IMPORT it in the others.
Just as with any function you define, if you want to use it in other units, they have to be told where to fetch it from.
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