Skip to content

Instantly share code, notes, and snippets.

@bubaflub
Created June 26, 2011 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bubaflub/1047177 to your computer and use it in GitHub Desktop.
Save bubaflub/1047177 to your computer and use it in GitHub Desktop.
crazy structs i need to fit into a StructView
/* Available random number generation algorithms. */
typedef enum
{
GMP_RAND_ALG_DEFAULT = 0,
GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */
} gmp_randalg_t;
/* Random state struct. */
typedef struct
{
mpz_t _mp_seed; /* _mp_d member points to state of the generator. */
gmp_randalg_t _mp_alg; /* Currently unused. */
union {
void *_mp_lc; /* Pointer to function pointers structure. */
} _mp_algdata;
} __gmp_randstate_struct;
typedef __gmp_randstate_struct gmp_randstate_t[1];
Main Question: How do I represent a gmp_randstate_t as a StructView?
a) The last line, "typedef __gmp_randstate_struct gmp_randstate_t[1];" means that a gmp_randstate_t is really an array of two __gmp_randstate_structs, right?
b) The union around a single void pointer is just the same size as a pointer, right?
c) gmp_randalg_t is typedef'd as an enum but that's just the same size as an integer, right?
d) I already have a function that returns a gmp_t StructView - is there a simple way to embed this stuff?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment