mpz_array_init documentation
Sisyphus
sisyphus1 at optusnet.com.au
Tue Jun 21 12:22:46 CEST 2005
Hi,
The documentation for mpz_array_init concludes by telling me that "There is
no way to free the storage allocated by this function. Don't call
`mpz_clear'!"
Yet I run the following program without any problems:
--- try.c ---
#include <stdio.h>
#include <malloc.h>
#include <gmp.h>
int main(void) {
mpz_t * a;
int count = 1000, bits = 200, i;
a = malloc(count * sizeof(mpz_t));
if(a == NULL) printf("Failed to allocate memory\n");
mpz_array_init(*a, count, bits);
// Assign some values
for(i = 0; i < count; ++i) mpz_set_ui(a[i],(i + 1) * 100);
// Check that the values are correct
for(i = 0; i < count; ++i) {
if(mpz_cmp_ui(a[i],(i + 1) * 100)) printf("%d: ERROR\n", i);
}
for(i = 0; i < count; ++i) mpz_clear(a[i]);
free(a);
printf("DONE\n");
return 0;
}
--- end ---
D:\C>gcc -o try.exe try.c -Wall -lgmp
D:\C>try
DONE
By my reading of the docs I should delete that line of code that contains
the mpz_clear() calls. Is that so ? Or are they meaning something else ?
Cheers,
Rob
More information about the gmp-discuss
mailing list