|
|
View previous topic :: View next topic |
Author |
Message |
chenzhuo
Joined: 17 Jan 2015 Posts: 8 Location: 美国
|
Problem in itoa while it's used in multiple unit |
Posted: Sat Feb 03, 2018 5:33 am |
|
|
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: 19540
|
|
Posted: Sat Feb 03, 2018 12:57 pm |
|
|
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. |
|
|
|
|
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
|