[Nickle] Nickle compiler bug

bart at po8.org bart at po8.org
Thu Sep 16 23:50:30 PDT 2004


Apparent behavior with octal numbers cheat-sheet:

   C compiler, GCC with default options:
     05938 yields "invalid digit '9' in octal constant" message
   libc atoi(), latest Debian libc:
     05938 is interpreted as decimal, so is 05737.  Modern
     atoi() apparently is decimal-only
   Nickle command line:
     05938 is interpreted as decimal.  05737 is interpreted
     as octal.  0o5938 yields "syntax error before 938". Ouch
   Nickle atoi(), no base argument:
     05938 is interpreted as 5, i.e., interpretation stops
     at the 9.  Same with 0o5938.

The Nickle behaviors in the presence of invalid digits are
just plain wrong: both the command line and atoi() should
throw exceptions for bogus non-whitespace and/or invalid
digits and/or quit trying to be clever about C-style octal
constants (when was the last time you used one, outside of
permission bits?) and simply require octal to be expressed
with 0o as in 0o5737.

I'll make the changes unless someone has a better suggestion.

	Bart

In message <E1C87Nj-0005k8-Mc at evo.keithp.com> you wrote:
> --===============0041476072==
> Content-Type: multipart/signed; boundary="==_Exmh_-1024653560P";
> 	micalg=pgp-sha1; protocol="application/pgp-signature"
> Content-Transfer-Encoding: 7bit
> 
> --==_Exmh_-1024653560P
> Content-Type: text/plain; charset=us-ascii
> 
> 
> Around 10 o'clock on Sep 16, bart at po8.org wrote:
> 
> > Take a look at the just-checked-in
> > examples/google-puzzle.5c.  It outputs an even answer :-),
> 
> Note that the output number has a leading zero, causing 'atoi' to 
> interpret it in octal.
> 
> I fixed it.  Now it outputs an odd number, but not the right one.  Given 
> the small values involved, checking actual primality works just fine and 
> does generate the right answer.
> 
> -keith
> 
> 
> 
> --==_Exmh_-1024653560P
> Content-Type: application/pgp-signature
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (GNU/Linux)
> Comment: Exmh version 2.3.1 11/28/2001
> 
> iD8DBQFBSjs7Qp8BWwlsTdMRAjcHAKC/pWy9stjuYkTlYHBjFx0fZ52nGgCfe+n/
> 26UoPxEmavnUkhXkhzV2AfQ=
> =newX
> -----END PGP SIGNATURE-----
> 
> --==_Exmh_-1024653560P--
> 
> 
> --===============0041476072==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
> 
> _______________________________________________
> Nickle mailing list
> Nickle at nickle.org
> http://nickle.org/mailman/listinfo/nickle
> 
> --===============0041476072==--
> 



More information about the Nickle mailing list