This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ExtUtils::CBuilder - Fix link() on Windows, broken in version 0.280226
[perl5.git] / pod / perlclib.pod
index c5fb455..b366c7f 100644 (file)
@@ -203,15 +203,26 @@ C<toUPPER_uni>, as described in L<perlapi/Character case changing>.)
  Instead Of:                 Use:
 
  atof(s)                     Atof(s)
- atoi(s)                     grok_atou(s, &e)
- atol(s)                     grok_atou(s, &e)
+ atoi(s)                     grok_atoUV(s, &uv, &e)
+ atol(s)                     grok_atoUV(s, &uv, &e)
  strtod(s, &p)               Nothing.  Just don't use it.
- strtol(s, &p, n)            grok_atou(s, &e)
- strtoul(s, &p, n)           grok_atou(s, &e)
+ strtol(s, &p, n)            grok_atoUV(s, &uv, &e)
+ strtoul(s, &p, n)           grok_atoUV(s, &uv, &e)
+
+Typical use is to do range checks on C<uv> before casting:
+
+  int i; UV uv; char* end_ptr;
+  if (grok_atoUV(input, &uv, &end_ptr)
+      && uv <= INT_MAX)
+    i = (int)uv;
+    ... /* continue parsing from end_ptr */
+  } else {
+    ... /* parse error: not a decimal integer in range 0 .. MAX_IV */
+  }
 
 Notice also the C<grok_bin>, C<grok_hex>, and C<grok_oct> functions in
 F<numeric.c> for converting strings representing numbers in the respective
-bases into C<NV>s.  Note that grok_atou() doesn't handle negative inputs,
+bases into C<NV>s.  Note that grok_atoUV() doesn't handle negative inputs,
 or leading whitespace (being purposefully strict).
 
 Note that strtol() and strtoul() may be disguised as Strtol(), Strtoul(),