Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: dead code, brain dead lilbrary Message-ID: <10310@hoptoad.uucp> Date: 19 Feb 90 07:35:12 GMT References: <1990Feb14.204332.24800@caen.engin.umich.edu> <20062@bellcore.bellcore.com> <10294@hoptoad.uucp> <2971@draken.nada.kth.se> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 30 In article <10294@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) writes: >>The proper way to write atoi on the Macintosh is: >>int atoi(StringPtr s) { long i; StringToNum(s, &i); return i; } > ~~~ ~~~~ ~~~~~~~~ In article <2971@draken.nada.kth.se> d88-jwa@nada.kth.se (Jon W{tte) writes: >Any sane compiler would complain. If you reurn a long, the >function should be declared long. If you use int, you're wide >open for all kinds of incompatibilities. Int is intended only >for holding "a small integer value", and you can never assume >it can take a value higher than 32767. (Look in the standard) Right, but atoi is explicitly defined in the C standard as returning an int (at least in K&R), so you can't change that. Basically, what you'll get is an incorrect result if you pass in a string representing a number that's too big for an int, which is what will happen with *any* atoi, not just this one. My point, anyway, was not that you should do this. You should use StringToNum as is. However, if you have a bunch of code lying around that uses atoi and it's too much trouble to convert, then you should define the routine as above -- with, if the compiler demands it, an (int) conversion on the return statement. -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com FROM THE FOOL FILE: "Women's wages are 56% of men's -- but that's not necessarily evidence of discrimination in employment." -- Clayton Cramer in news.groups and soc.women