This is the mail archive of the gcc-help@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: C and zero-sized arrays - what is the standard?


> 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.


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