<< Previous | Next >>

strtol

NEAR SYNTAX: long _n_strtol( char * sptr, char ** tailptr, int base );

FAR SYNTAX: long _f_strtol( char far *sptr, char far * far * tailptr, int base );

NOTE By default, strtol() is defined to _n_strtol().

Description

ANSI string to long 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

sptr
String to convert.

tailptr
Assigned the last position of the conversion. The next conversion may resume at the location specified by *tailptr.

base
Indicates the radix of conversion.

Return value

The long integer.

Library

STRING.LIB

See also

atoi, atol


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