Monthly Archives: mai 2007

Zero-extent array members

Posted by on mai 01, 2007
Fără categorie / No Comments

Some compilers, such as GCC or IBM’s compiler have a C extension that allows for a zero-extent array members of a structure to be declared:

struct inode{
//other members
char data[0];
};

They are very useful if you have a structure for a variable-length object. Until they are allocated the zero-extent members will not take up any memmory. When you have to allocate memory for such a structure, you can do it this way:

struct inode *ind = (struct inode*) malloc(sizeof(struct inode) + size_of_the_array);

You have to keep in mind that this is a language extension. The C99 standard only allows flexible array members, which are defined as

char array[];

(without the 0) and behave somewhat differently. You can find out more about the subject in the GCC Manual.

New blog – Coder Tricks

Posted by on mai 01, 2007
Fără categorie / No Comments

With the help of some colleagues, I just launched a new blog. It’s called Coder Tricks and it will contain programming tricks that the teachers don’t usually bother to tell you in programming courses. Hope you like it!

If you wish to offer any kind of feedback, you’re more than welcomed to contact us at codertricks@strainu.ro.