This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] ABI change for variable sized types


On Wed, 14 Jul 2004, Richard Henderson wrote:

> The cases of variable sized structures as GCC extensions in C are,
> as far as I can tell, only valid in the context of nested functions.
> Which means that the functions are private to the translation unit,
> and thus there is no ABI change.

You can pass pointers to such functions around, but the testcase I tried
to create gives an ICE on every version of GCC I tried from 2.6.3 onwards,
so at least for this case there is no practical ABI problem.  The more I
consider what these types mean in the context of how C99 VLAs might be
properly implemented, the more I conclude we don't want this extension
(variable-sized structures in C).

First translation unit:

#include <stdio.h>
#include <string.h>

int bar (int (*)(), int, void *);

int
main(int argc, char **argv)
{
  struct s { int a; char b[argc]; };
  int nested (struct s x) { return x.a + sizeof(x); }
  struct s t;
  memset (&t, 0, sizeof(t));
  t.a = 123;
  printf("%d\n", bar (nested, argc, &t));
  return 0;
}

Second translation unit:

int
bar (int (*fp)(), int argc, void *ap)
{
  struct s { int a; char b[argc]; };
  struct s *sp = ap;
  return fp(*sp);
}

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]