1

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

Mats Petersson
130k15 gold badges147 silver badges233 bronze badges
asked Apr 19, 2014 at 13:41
3
  • 1
    Are you wanting a solution in C or C++? The answers may be very different depending on which you choose. Commented 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. Commented Apr 19, 2014 at 13:55
  • Removing C++ tag, since it seems like C++ isn't really the language being asked about. Commented Apr 19, 2014 at 13:59

1 Answer 1

1

Following will work, assuming memory allocated properly for key.s and initialized

nmod_poly_t poly; 
poly[0] =key.s[0][0];
answered Apr 19, 2014 at 14:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.