Compiling Issue
Francesco Barbato
barbafrank at me.com
Sun Mar 9 15:06:24 UTC 2014
Good morning,
this is the second time I send this email, last time the attachments were lost.
i'm sorry if my english sucks, unfortunately is not my native language.
When i try to compile my code i receive 2 errors from Xcode:
1. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/memory:1739:61: Object expression of non-scalar type '__mpz_struct [1]' cannot be used in a pseudo-destructor expression
2. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/memory:1684:13: Array 'new' cannot have initialization arguments
here is my code:
//
// main.cpp
// isPrime
//
// Created by Francesco on 07/02/14.
// Copyright (c) 2014 Francesco. All rights reserved.
//
#include <iostream>
#include <vector>
#include </usr/local/include/gmp.h>
bool isPrime(long n)
{
bool flag = true;
std::vector<mpz_t> row; row.resize(n/2+1);
mpz_init(row[0]);
mpz_set_si(row[0], long(1));
for(int i=1; i<n/2+1; i++)
{
mpz_init(row[i]);
mpz_mul_si(row[i],row[i-1],(n-i+1));
mpz_div_ui(row[i],row[i],i);
}
mpz_t resto;
mpz_init(resto);
for(long i=1; i<(n/2+1); i++)
{
mpz_mod_ui(resto,row[i],n);
if(mpz_get_si(resto) != 0)
{
flag = false;
break;
}
}
return flag;
}
int main(int argc, const char * argv[])
{
std::cout << "Inserisci il numero \n"; //it's italian 'cause i am italian
long n;
std::cin >> n;
if(isPrime(n) == true)
{
std::cout << "Il numero " << n << " é primo\n";
}
else
{
std::cout << "Il numero " << n << " non é primo\n";
}
return 0;
}
i'd like to know if is my fault, like if i made a mistake in my code, or is an error in your library.
thanks in advance,
Francesco Barbato
More information about the gmp-discuss
mailing list