Hi Bruno, On Fri, Jul 19, 2024 at 12:34:39AM GMT, Bruno Haible wrote: > Alejandro Colomar wrote: > > > - Some systems return "wrong" errno values. Example: [1] > > > - Some systems fail with ENOMEM when memory is tight. Who says that > > > an implementation of strtol() cannot use malloc() ? Some > > > implementations > > > of strtod() do use malloc(). > > > > > > So, what you call "dead code", I call "defensive programming". I would not > > > like to apply this patch. > > > > Makes sense. I think we should document that possibility in the manual > > page. > > Well, I wouldn't want to document just _theoretical_ platforms.
While it may be theoretical for strtol(3), you said it was real for strtod(3), and strtod(3) defers to strtol(3) for the example program. We should provide a portable example of use of strtod(3), and rather than writing another example for strtod(3), maybe we could improve the strtol(3) one for theoretical implementations. > The set of > manual pages has a certain scope, regarding platform, probably Linux > (and Hurd, maybe?). It's the behaviour on these platforms which should > be documented, nothing more, nothing less. Not really. We do document portability to other Unix systems. Mainly the BSDs, but in some important cases we document others. > > Defensive programming means to imagine other behaviours that could > possibly occur. It is subjective; some programmers want to be more cautious > than others. > > > Maybe say that other errno values are possible in some systems? > > Other errno values are always possible, as far as I understand POSIX. > <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap01.html> > section 1.2 ERRORS. True. > It would be overkill to state this in hundreds of manual pages, IMO. strtol(3) is special-enough regarding errors, that it might make sense. Even if we don't mention it in ERRORS, it would make sense to fix the example program to make it portable. > > Bruno Have a lovely night! Alex -- <https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature