My goal was to reduce the amount of memory required - I knew that there might be a problem as soon as I looked at what was happening with the memory dump
Basically (for clarification), yes it was a "Sieve of Eratosthenes alg" that I was trying to implement. It was suggested as an alternative to add up all the prime numbers from 0 to 2,000,000. I have a fairly fast function to calculate if a number is a prime, so my original approach used a for() loop to and that function to get the sum - I'm just curious of the other approach... Send me a message if you want my "is_prime()" function... My fastest time to add up all the primes from 0 to 2,000,000 was 1.57sec -> See if you can beat it :P
I played around with this code a bit...
Code:
int main(void)
{
union
{
struct
{
int val1 : 1;
} sievebound_bit[8];
char sievebound_byte;
} data;
data.sievebound_byte = 0;
printf("%x ",data.sievebound_byte);
data.sievebound_bit[0].val1 = 1;
printf("%x ",data.sievebound_byte);
data.sievebound_bit[1].val1 = 1;
printf("%x ",data.sievebound_byte);
data.sievebound_bit[0].val1 = 0;
printf("%x ",data.sievebound_byte);
data.sievebound_bit[3].val1 = 1;
printf("%x ",data.sievebound_byte);
return EXIT_SUCCESS;
}
It clearly didn't work for anything else than [0] - I think that the only think appropriate for this code is to dig a large hole, put it in there, and fill the hole as fast a possible... Actually, I think that the delete key will do the job - and that way I don't have to put my computer in a hole in the ground...
Bottom line is that this approach does not work