forked from freezer333/cppwebify-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimeapi.cpp
More file actions
28 lines (22 loc) · 658 Bytes
/
primeapi.cpp
File metadata and controls
28 lines (22 loc) · 658 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <stdio.h>
#include <functional>
#include "exchange.h"
#include "prime_sieve.h"
#include "primeapi.h"
//using namespace std;
// it's assumed primes is a pre-allocated array of at least "under" size.
// the function fills in the primes array with all prime numbers less
// than "under". It returns the number of prime numbers
// found by the prime_sieve algorithm.
EXPORT int getPrimes(int under, int primes[]) {
int count = 0;
Exchange x(
[&](void * data) {
int * iptr = (int *) data;
primes[count++] = *iptr;
}
);
generate_primes(under, (void*)&x);
return count;
}