[M3devel] Interpretation of numbers
Dariusz Knociński
dknoto at next.com.pl
Thu Dec 30 23:14:42 CET 2010
Hi all,
in my spare time I write a lexer to Modula-3 for Scintilla library and I found
mistake in numeric constants with explicitly given base number system, eg. octal
numbers.
This simple program in C generates compiler error:
#include <stdio.h>
int main( void )
{
unsigned o;
o = 0787;
printf( "o = %u\n", o );
return 0;
}
in gcc 4.5.1 20100924 (Red Hat 4.5.1-4) this is:
Numbers.c: In function ‘main’:
Numbers.c:7:6: error: invalid digit "8" in octal constant
but CM3 with analogical program:
MODULE Numbers EXPORTS Main;
IMPORT IO, Fmt;
VAR
o : CARDINAL;
BEGIN
o := 8_787;
IO.Put( "o = 8_" & Fmt.Unsigned( o, 8 ) & "\n" );
END Numbers.
compiles his properly and the program generate output:
o = 8_1007
This is correct number, 519 decimal, but similar mistakes can be difficult to find.
Best regards
Dariusz Knociński.
More information about the M3devel
mailing list