[comp.lang.c] TC thanks & another question...

robertl@killer.UUCP (Robert Lord) (07/31/87)

First off I want to thank all of those who answered my question on long numbers
and how to change strings to integers.  I have got the long numbers working
fine, except now I need some help with atol().

data.sqle is defined in my structure (an include file) as type 'long int'.
data.sqft is a string consisting of some numeral value (yes, with quotes
and starting at [0] :-).  Now why does the command:

data.sqle = atol(data.sqft);

go crazy when I give it anything larger than 32000 (by 'going crazy' I mean
giving the usual wierd numbers that have no connection with the origional
one at all)?  Please tell me this is not a bug with TC.....


                Thanks,
                  Robert Lord
                    ..!ihnp4!killer

gnu@hoptoad.uucp (John Gilmore) (08/03/87)

robertl@killer.UUCP (Robert Lord) wrote:
> data.sqle is defined in my structure (an include file) as type 'long int'.
> data.sqft is a string consisting of some numeral value (yes, with quotes
> and starting at [0] :-).  Now why does the command:
> 
> data.sqle = atol(data.sqft);
> 
> go crazy when I give it anything larger than 32000 (by 'going crazy' I mean
> giving the usual wierd numbers that have no connection with the origional
> one at all)?

Let me guess.  Did you declare:

	long atol();

somewhere in your source file?  Without this, the compiler does not know
that atol() is returning a 32-bit result, if your ints are 16 bits.

I recommend running "lint" on your programs, it will catch things like
this without your having to debug it.
-- 
{dasys1,ncoast,well,sun,ihnp4}!hoptoad!gnu	     gnu@postgres.berkeley.edu
Alt.all: the alternative radio of the Usenet.

jgy@hropus.UUCP (John Young) (08/06/87)

Posting-Front-End: GNU Emacs 18.47.1 of Tue Jul  7 1987 on opus (usg-unix-v)



Did you define atol as being a function returning a long ??
The default is an int which may be 16 bits on your machine