Path: utzoo!attcan!uunet!mcsun!sunic!draken!d88-jwa From: d88-jwa@nada.kth.se (Jon Watte) Newsgroups: comp.sys.mac.programmer Subject: Re: Re: dead code, brain dead lilbrary Message-ID: <2977@draken.nada.kth.se> Date: 19 Feb 90 14:09:03 GMT References: <1990Feb14.204332.24800@caen.engin.umich.edu> <20062@bellcore.bellcore.com> <10294@hoptoad.uucp> <2971@draken.nada.kth.se> <166.25e0277b@waikato.ac.nz> Reply-To: d88-jwa@nada.kth.se (Jon W{tte) Organization: Royal Institute of Technology, Stockholm, Sweden Lines: 34 In article <166.25e0277b@waikato.ac.nz> ccc_ldo@waikato.ac.nz writes: >In article <2971@draken.nada.kth.se>, d88-jwa@nada.kth.se (Jon Watte) >>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; } >> ~~~ ~~~~ ~~~~~~~~ >>Any sane compiler would complain. If you reurn a long, the I meant should. English is not my native language. >>function should be declared long. If you use int, you're wide >>open for all kinds of incompatibilities. Int is intended only >The compiler converts the type of the "return" expression to >match the type returned by the function. Try changing the type >of the above "atoi" function from "int" to "short", and have a >look at the generated code, to see what I mean. Try changing half of the longs you use to shorts, randomly, and see how long your program copes. One minute ? Two minutes ? assigning a long to an inte is _never_ a good practise - and in this case, it happens to work on MPW C 3 but not earlier or other Mac compilers. (Work == give the desired effect) In general, one should never use ints other than as small indicies in loops... Anyone think of another use for ints ? h+ -- --- Stay alert ! - Trust no one ! - Keep your laser handy ! --- h+@nada.kth.se == h+@proxxi.se == Jon Watte longer .sig available on request