C’s Designated Initializers

While working with FUSE C API, I came across the follow snippets of code which caught me eyes:

static struct fuse_operations xmp_oper = {
    .getattr  = xmp_getattr,
    .access   = xmp_access,
    .readlink = xmp_readlink,
    .fsync    = xmp_fsync,

Those style of struct initialization are called designated Initializers, and apparently they were introduced in ISO C99 (it is also existed as a GNU extension to C90 as well).

A thread on Hacker News has an interesting discussion on the topic (such as the fact that it is extensively used in Linux device driver code, e.g., [1]), as well as many informative links [2, 3] and even a suggestion on a book that describes new features that were introduced in C99.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s