<< Previous | Next >>

strtod

NEAR SYNTAX: float _n_strtod( char * s, char ** tailptr );

FAR SYNTAX: float _f_strtod( char far * s, char far * far * tailptr );

NOTE By default, strtod() is defined to _n_strtod().

Description

ANSI string to float conversion.

For Rabbit 4000+ users, this function supports FAR pointers. The macro USE_FAR_STRING will change all calls to functions in this library to their far versions by default. The user may also explicitly call the far version with _f_strfunc, where strfunc is the name of the string function.

Because FAR addresses are larger, the far versions of this function will run slightly slower than the near version. To explicitly call the near version when the USE_FAR_STRING macro is defined and all pointers are near pointers, append _n_ to the function name, e.g. _n_strtod. For more information about FAR pointers, see th Dynamic C User's Manual or the samples in Samples/Rabbit4000/FAR/.

WARNING: The far version of strtod is not backwards compatible with near pointers due to the use of a double pointer. The problem is that char ** tailptr is a 16-bit pointer pointing to another 16-bit pointer. The far version, char far * far * tailptr, is a 32-bit pointer pointing to a 32-bit pointer. If you pass a double near pointer as the argument to the double far pointer function, the double dereference (**tailptr) of the double pointer will attempt to access a 32-bit address pointed to by the passed near pointer. The compiler does not know the contents of a pointer and will assume the inner pointer is a 32-bit pointer. For more information about FAR pointers, please see the Dynamic C User's Manual .

In the following examples:

   

[ ] = 1 byte
[ ][ ][x][x] indicates a NEAR address (16 bit) upcast to FAR

Passing a "char far * far * ptr" as tailptr:

   

ADDRESS:        DATA:
[ ][ ][x][x]    [y][y][y][y] (tailptr)
[y][y][y][y]    [z][z][z][z] (*tailptr)
[z][z][z][z]    [Correct contents] (**tailptr)

Passing a 'char ** ptr' as tailptr: Note the first pointer can be upcast to FAR but the compiler doesn't know to upcast the internal pointer.

   

ADDRESS:         DATA:
[ ][ ][x][x]     [ ][ ][y][y] (tailptr)
[ ][ ][y][y]     [?][?][z][z] (*tailptr)
[?][?][z][z]     [Incorrect contents] (**tailptr)

Parameters

s
String to convert.

tailptr
Pointer to a pointer of character. The next conversion may resume at the location specified by *tailptr.

Return value

The float number represented by "s."

Library

STRING.LIB

See also

atof


Dynamic C Functions << Previous | Next >> rabbit.com