On Sun, 2025-02-02 at 16:45 +0000, Joe Finney wrote: > Is it straightforward to make a union that references itself? > > union u { > int x; > union u *p; > } > > With structs, I can use gcc_jit_context_new_opaque_struct, but there > doesn't seem to be an equivalent for unions.
On most reasonable computers, every data pointer has the same size and representation (so same size, same alignment, internally represented as some "word" eg 64 bits). So you could at least make the libgccjit calls to build the equivalent of union u { int x; void* p; }; and then use libgccjit casts to transform the p to a union u* pointer. Assuming your libgccjit context has some optimization enabled, the generated code should be the same. BTW if you want to generate quickly unoptimal code you may consider (instead of libgccjit) using GNU lightning on https://www.gnu.org/software/lightning/ or asmjit on https://asmjit.com/ In some cases, just generating C or C++ temporary code compiled to a plugin could be simpler. See https://arxiv.org/abs/1109.0779 or the code on https://github.com/bstarynk/bismon or on https://github.com/bstarynk/misc-basile/blob/master/manydl.c Regards from near Paris in France PS. My open source project is an inference engine on https://github.com/RefPerSys/RefPerSys/ -- Basile STARYNKEVITCH <bas...@starynkevitch.net> 8 rue de la Faïencerie 92340 Bourg-la-Reine, France http://starynkevitch.net/Basile & https://github.com/bstarynk