Compiling Issue
Sam Rawlins
sam.rawlins at gmail.com
Sun Mar 9 16:32:31 UTC 2014
Hi Francesco,
When writing in C++, I would recommend using the C++ Interface. It is very
well-documented:
https://gmplib.org/manual/C_002b_002b-Class-Interface.html#C_002b_002b-Class-Interface
Also, Chris Croughton's response from 2005: "mpz_t is defined as a
1-element array, to make using the C GMP functions easier, which blows the
C syntax for containers and new."
http://bytes.com/topic/c/answers/137867-gmp-cannot-operate-vector-mpz_t
On Sun, Mar 9, 2014 at 8:06 AM, Francesco Barbato <barbafrank at me.com> wrote:
> 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
>
>
>
>
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss
>
--
Sam Rawlins
More information about the gmp-discuss
mailing list