problems with structures and mpz_t

Décio Luiz Gazzoni Filho decio at decpp.net
Mon Mar 28 02:12:27 CEST 2005


On Sunday 27 March 2005 19:29, Wing Lian wrote:
> I am trying to use structures containing mpz_t variables so that I can sort
> according to certain criteria.
>
> struct individual {
>     mpz_t int1, int2;
>     unsigned long int int3;
> };
> ..
> int n;
> n = 10; //number of elements
> individual *gen1;
> gen1 = (individual *)malloc(sizeof(individual)*n);
> for (i=0; i<n; i++) {
>  mpz_init(*(gen1 + i).int1);
> }
> ..
>
> when compiled, the error returns
>  error: request for member `int1' in `(gen1 + (+(i * 40)))', which is of
> non-class type `individual*'
>
> I'm pretty sure I'm using the correct syntax so I'm not sure what's going
> on.

I *believe* (am not sure, and neither have I tested) that you should write 
(*(gen1 + i)).int1, or (gen1 + i)->int1, or (God forbid) you aid people who 
are reading your code a little by writing gen1[i].int1.

Are you going to submit this to an obfuscated code contest of some sort?

Décio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: not available
Url : http://gmplib.org/list-archives/gmp-discuss/attachments/20050328/bf918972/attachment.bin


More information about the gmp-discuss mailing list