A
Albert van der Horst
I have the following program that gives consistently a segfault
with
--------------------
46344 1
46345 1
46346 1
46347 1
46348 1
46349 0
Segmentation fault
-------------------
The program itself doesn't give any complaints with gcc 4.4
on a stable Debian.
It is a classical prime sieve.
I can't find any fault with it.
--------------------------
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
#define BYTE uint8_t
/* largest number */
#define MAXSIZE 20000000
#define SIZE 2000000
long int TheLimit;
/*****************************************************************************/
/* */
/* Fill the `nprimes' table up to `n' */
/* */
/*****************************************************************************/
static BYTE composite[ MAXSIZE+1];
void fill_primes( int n)
{
int i,j;
assert(n<=MAXSIZE);
for (i=0;i<=n; i++) composite = 0;
for ( i=2; i<=n; i++)
{
printf("%d %d \n",i,composite);
if (!composite)
{
for (j=i*i; j<=n; j+=i) composite[j] = 1;
}
}
}
int main( int argv, char** argc)
{
int i;
TheLimit = atoi(argc[1]);
printf("n= %d\n",TheLimit);
fill_primes(TheLimit);
printf("primes ready\n");
}
------------------------------
Must I suspect the installation of my compiler?
Groetjes Albert
with
--------------------
46344 1
46345 1
46346 1
46347 1
46348 1
46349 0
Segmentation fault
-------------------
The program itself doesn't give any complaints with gcc 4.4
on a stable Debian.
It is a classical prime sieve.
I can't find any fault with it.
--------------------------
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
#define BYTE uint8_t
/* largest number */
#define MAXSIZE 20000000
#define SIZE 2000000
long int TheLimit;
/*****************************************************************************/
/* */
/* Fill the `nprimes' table up to `n' */
/* */
/*****************************************************************************/
static BYTE composite[ MAXSIZE+1];
void fill_primes( int n)
{
int i,j;
assert(n<=MAXSIZE);
for (i=0;i<=n; i++) composite = 0;
for ( i=2; i<=n; i++)
{
printf("%d %d \n",i,composite);
if (!composite)
{
for (j=i*i; j<=n; j+=i) composite[j] = 1;
}
}
}
int main( int argv, char** argc)
{
int i;
TheLimit = atoi(argc[1]);
printf("n= %d\n",TheLimit);
fill_primes(TheLimit);
printf("primes ready\n");
}
------------------------------
Must I suspect the installation of my compiler?
Groetjes Albert