Using the mpz_t type in a function

47 views
Skip to first unread message

Richard Marton

unread,
Oct 26, 2012, 1:28:25 PM10/26/12
to mpir-...@googlegroups.com
Hello!

I wrote a void c++ function which uses the mpz_t type numbers and writes it's output to stdout.

void primkereso(int bitszam){

...

mpz_out_str(stdout, 10, prim);
}

The problem is i want to store the prim variable outside of the custom function. I have made and external mpz_t variable, and i want to mpz_set(d,primkereso(16));
Can i make this function return an mpz_t number?




I am trying to get the

Bill Hart

unread,
Oct 26, 2012, 1:39:08 PM10/26/12
to mpir-...@googlegroups.com
You can pass the mpz_t variable as a parameter to your function rather
than define it internally. The mpz_t type is set up to essentially
pass by reference, so any modifications you make inside the function
are also available outside it.

void primkereso(int bitszam, mpz_t prim){
...
mpz_out_str(stdout, 10, prim);
}

....

mpz_t prim;
mpz_init(prim);
primkereso(123, prim);

Does this answer your question?

Bill.
> --
> You received this message because you are subscribed to the Google Groups
> "mpir-devel" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mpir-devel/-/vjZBNPGG0w0J.
> To post to this group, send email to mpir-...@googlegroups.com.
> To unsubscribe from this group, send email to
> mpir-devel+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mpir-devel?hl=en.

Richard Marton

unread,
Oct 26, 2012, 3:16:50 PM10/26/12
to mpir-...@googlegroups.com
Yes, it helped. I modified the primkereso function to use two new references, and it works nicely.

Thank you for your time!
Reply all
Reply to author
Forward
0 new messages