Bill Allombert on Mon, 13 Dec 2004 17:41:42 +0100

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Alternative definition of the GEN type.

Hello PARI developers,

Apparently current PARI/GP CVS does not build with gcc 3.x due to
strict aliasing problem. Apparenlty setting -fno-strict-aliasing 
work-around the problem.

This is due to recent changes to make gmael et al. valid lvalues.

#define gmael(m,x1,x2)          (((GEN**)   (m))[x1][x2])

Unfortunately mixing GEN** and GEN* break aliasing rules.

Probably the best way to implement the GEN type would be to do:
union GEN_s
  long l;
  ulong u;
  union GEN_s *g;

typedef union GEN_s *GEN;

#define gel(x,i) ((x)[i].g)
#define gmael(x,i,j) gel(gel(x,i),j)
#define el(x,i) ((x)[i].l)
#define uel(x,i) ((x)[i].u)
This way gel(x,i), el(x,i) and uel(x,i) are valid lvalues without
requiring any cast.  
This is data-compatible with the current definition of GEN as long *
but mixing the two will reintroduce the strict aliasing problems we are
trying to avoid.