mpz_init(x) does not set x's value to zero

Will Galway galway at math.uiuc.edu
Thu Feb 2 19:19:57 CET 2012


Just to follow-up on Torbjorn's reply, your example seems to have little 
to do with properly using GMP.

Only someone who's familiar with the precise details of GMP's 
implementation should be using the kind of pointer operations that your 
program uses.  Your program shows no signs of demonstrating that the 
initialization goes wrong, but rather that you are not using GMP correctly.

After your calls to "mpz_init(...)" you should go on to use functions 
like "mpz_add(...)", "mpz_mul(...)", "gmp_printf(...)", etc. in order to 
do arithmetic on the numbers and to print your results.  You should read 
through the manual to find some examples of proper coding style, or see 
the "demos" subdirectory of the GMP distribution.

-- Regards, Will

On 2012-02-02 12:46, Christina Vichou wrote:
> • The GMP version number, and if pre-packaged or patched then say so.
> • A test program that makes it possible for us to reproduce the bug. Include instructions on
> how to run the program.
> • A description of what is wrong. If the results are incorrect, in what way. If you get a crash,
> say so.
> • If you get a crash, include a stack backtrace from the debugger if it’s informative (‘where’
> in gdb, or ‘$C’ in adb).
> • Please do not send core dumps, executables or straces.
> • The configuration options you used when building GMP, if any.
> • The name of the compiler and its version. For gcc, get the version with ‘gcc -v’, otherwise
> perhaps ‘what ‘which cc‘’, or similar.
> • The output from running ‘uname -a’.
> • The output from running ‘./config.guess’, and from running ‘./configfsf.guess’
> (might be the same).
> • If the bug is related to ‘configure’, then the compressed contents of ‘config.log’.
> • If the bug is related to an ‘asm’ file not assembling, then the contents of ‘config.m4’ and
> the offending line or lines from the temporary ‘mpn/tmp-<file>.s’.
>
> Hello,
>
> I use fedora 14 and i have installed gnu mp 5.0.3 in my acer lap top.
> There is a really unexpected problem. I simply try to compile the next lines:
>
>             source code:
> ------------------------------------------------------------------------------------------------
> #include<stdio.h>
> #include<gmp.h>
>
> main(int argc, char **argv){
>
> int a=5;
>
> mpz_t kal, b;
>
> mpz_init(kal);
> mpz_init(b);
>
> mpz_t *point=&kal;
>
> printf("a=%d\n", a);
> printf("*(&a)=%d\n", *(&a));
>
> printf("*(&kal)=%d\n", *(&kal));
> printf("&kal=%d\n",&kal);
> printf("*point=%d\n", *point);
> printf("&point=%d\n",&point);
> printf("kal=%d\n", kal);
>
> printf("b=%d\n", b);
>
> mpz_clear(kal); mpz_clear(b);
>
> return 0;
> }
>
> and the result in my system is every time something like:
> ----------------------------------------------------------------------------------------
>
> a=5
> *(&a)=5
> *(&kal)=453871456
> &kal=453871456
> *point=453871456
> &point=453871432
> kal=453871456
> b=453871440
>
> As you san see i use *,&  and an int type variable in order to find in which cases the initialization goes wrong. I can tell that the problem happens every time i want to initialize an mpz_t variable..
>
> I really need help with this instantly.
> Thank you very much.
>   		 	   		
> _______________________________________________
> gmp-bugs mailing list
> gmp-bugs at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-bugs


More information about the gmp-bugs mailing list