C and zero-sized arrays - what is the standard?
Alexandre Courbot
Alexandre.Courbot@lifl.fr
Thu Sep 18 13:24:00 GMT 2003
> This is for my knowlege in which kind
> of situations you make use of these
> type of structure definitions.
We are using this to store the virtual methods table that belongs to classes
meta-data in an object-oriented operating system. Every class is defined by
the same structure (CardClass), but they each class have different methods
and therefore the number of methods is not fixed (but known statically).
Using a pointer that we would allocate is not an option. First, because we are
in the kernel-space of the operating system, and second, because this
operating system is designed for very small and limited embedded systems
(typically smartcards). By declaring a variable-length table of virtual
methods we are sure that the vtable will be located right with the rest of
the structure (and not allocated god-knows-where). This makes it possible to
write smaller, more efficient code and saves us a pointer to the vtable. And
yes, 4 bytes are worth saving on a smartcard. ;)
Alex.
More information about the Gcc-help
mailing list