[Shootout-list] nsieve OCaml Python programs not using true & false
Dima Dorfman
d+shootout@trit.org
Tue, 22 Feb 2005 01:44:05 +0000
Isaac Gouy <igouy2@yahoo.com> wrote:
> > > do not use a sequence of what OCaml and Python provide as boolean
> > > values.
> > >
> > > Is that correct?
> >
> > Correct (at least for OCaml, I didn't check Python). But then again,
>
> > neither does GCC, which fully supports the C99 Boolean datatype.
>
> Oh! I only just corrected the gcc entry to use Dima Dorfman's later
> code - Dima could it use C99 Boolean instead of a char array?
Sure, just include stdbool.h and change "char a[m]" to "bool a[m]". No
other changes are necessary. It shouldn't affect the timings; gcc 3.4
defines _Bool as a char anyway (at least it does on FreeBSD).
--- nsieve.c~ Sat Dec 18 10:35:14 2004
+++ nsieve.c Tue Feb 22 01:25:28 2005
@@ -5,6 +5,7 @@
*/
#include <limits.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -14,7 +15,7 @@
nsieve(uintmax_t m)
{
uintmax_t count, i, j;
- char a[m];
+ bool a[m];
memset(a, 1, sizeof(a));
count = 0;