develooper Front page | perl.perl5.porters | Postings from January 2001

Re: [PATCH] pod/perlclib.pod - Replacements for C library functions

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
January 31, 2001 06:09
Subject:
Re: [PATCH] pod/perlclib.pod - Replacements for C library functions
Message ID:
20010131140944.C76607@plum.flirble.org
On Wed, Jan 31, 2001 at 01:39:40PM +0000, Simon Cozens wrote:
> Just an idea I had...

A good idea I think

Specific things I notice:

> +    atof(s)                     Atof(s)
> +    atol(s)                     Atol(s)
> +    stdtod(s, *p)               Nothing. Just don't use it.
> +    strtol(s, *p, n)            Strtol(s, *p, n)
> +    strtoul(s, *p, n)           Strtoul(s, *p, n)

I don't think we're warning in any way for the case where the user configures
with long doubles, but we can't fake a long double Atof:

#if !defined(Perl_atof) && defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE)
#   if !defined(Perl_atof) && defined(HAS_STRTOLD)
#       define Perl_atof(s) (NV)strtold(s, (char**)NULL)
#   endif
#   if !defined(Perl_atof) && defined(HAS_ATOLF)
#       define Perl_atof (NV)atolf
#   endif
#   if !defined(Perl_atof) && defined(PERL_SCNfldbl)
#       define Perl_atof PERL_SCNfldbl
#       define Perl_atof2(s,f) sscanf((s), "%"PERL_SCNfldbl, &(f))
#   endif
#endif
#if !defined(Perl_atof)
#   define Perl_atof atof /* we assume atof being available anywhere */
#endif
#if !defined(Perl_atof2)
#   define Perl_atof2(s,f) ((f) = (NV)Perl_atof(s))
#endif

Note how it can end up with using atof() even in the long double case.

Atol() can end up as 32 bit when atoll doesn't exist (eg BSD, where there's
no atoq, but there is strtoq)

#   if defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_ATOLL)
#       define Atol	atoll
#   else
#       define Atol	atol
#   endif

Strtol and Strtoul should be OK for all "64bit" configurations assuming
they are sane enough to define one of strtoll, strtoq or just have real
64 bit longs (oh and have strtol, which we allow them not to have)

By "should" I mean anything that can go wrong will go wrong
We cannot be 100% certain that we have Strtol and Strtoul defined, but if
you don't have them, it's probably the least of your problems
[you've probably already been told to find an ANSI compiler]

However, we can't be sure that Strtol or Strtoul are actually able to
cope with longer IVs and UVs.

I was going to say should configure be enforcing "you can't use long longs
if I can't find a way to convert them" but for the core this isn't a problem,
as we can roll our own base 10 conversion. This still leaves some problems
for extensions if they really really want to do locale based number groupings
or things other than base 10.
[although I was also proposing to redo scan_hex, scan_oct with counterparts
that return UVs, but I was waiting until HP-UX is happy]

[in Blue Peter style I can do a "here's one I prepared earlier" (at least
for sv conversion) as it's sitting on a hard disk
Patch wanted?
]

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About