mcman
Joined: 23 Jan 2007 Posts: 8 Location: Corvallis, OR
|
strtoul issue in stdlib.h |
Posted: Tue Jan 23, 2007 1:48 pm |
|
|
I have a project that utilizes an 18F8722. I'm using the strtoul function to parse through a space delimited series of parameters. In using this function, I believe I've discovered an issue.
My code is something like this:
char *params;
params = &something;
strtoul(params, ¶ms, 10);
The issue is with the second argument to strtoul. It is supposed to give you an "end pointer" to where the strtoul parsing algorithm left off when it completed. I noticed, however, that my pointer would advance on return from strtoul like this:
0x01FE, 0x01FF, 0x0100......
instead of:
0x01FE, 0x01FF, 0x0200......
That's because the implementation of strtoul in stdlib.h casts the second parameter as type char. Since the endpointer parameter is essentially a pointer to a pointer, it should be cast to the data type required to store an address, not a 'char' data type. By modifying the strtoul library function to cast the second argument as an int16 throughout the function, everything then works just fine. |
|