I need to hold a dynamic array of structs.
The types are defined like this. I'm not able to change those, because they are given by a library called flint (library for fast number theory).
typedef struct
{
mp_ptr coeffs;
slong alloc;
slong length;
nmod_t mod;
} nmod_poly_struct;
typedef nmod_poly_struct nmod_poly_t[1];
and my struct is defined like this:
typedef struct {
mp_limb_t D;
mp_limb_t length;
nmod_poly_t *s;
} she_key_symmetric_t;
So my problem is to hold a set of nmod_poly_t objects. I initialize them and want so store them in the array.
nmod_poly_t poly;
nmod_poly_init(poly);
she_key_symmetric_t key;
// init and stuff
key.s[0] = poly; // This line does not work, because
// it always says "array type 'nmod_poly_t' (aka
// 'nmod_poly_struct[1]') is not assignable"
In the next step I have to get the values back out of the array
she_key_symmetric_t key;
// fully initialized key
nmod_poly_t poly = key.s[0];
So how do I need to declare my dynamic array s to store my strucs inside it?
Thanks in advance
-
1Are you wanting a solution in C or C++? The answers may be very different depending on which you choose.Edward– Edward2014年04月19日 13:54:17 +00:00Commented Apr 19, 2014 at 13:54
-
nmod_poly_t poly = key.s[0]; => nmod_poly_t poly; poly[0] =key.s[0][0]; actually works. Plain C is preferred.Arndt Bieberstein– Arndt Bieberstein2014年04月19日 13:55:30 +00:00Commented Apr 19, 2014 at 13:55
-
Removing C++ tag, since it seems like C++ isn't really the language being asked about.Mats Petersson– Mats Petersson2014年04月19日 13:59:24 +00:00Commented Apr 19, 2014 at 13:59
1 Answer 1
Following will work, assuming memory allocated properly for key.s and initialized
nmod_poly_t poly;
poly[0] =key.s[0][0];