1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Initializing structure members</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="conventions.html" title="Chapter&#160;10.&#160;Routines and Conventions"><link rel="prev" href="conventions-borkedcompile.html" title="Breaking Compilation"><link rel="next" href="conventions-gnu-extns.html" title="GNU Extensions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Initializing structure members</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="conventions-borkedcompile.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;10.&#160;Routines and Conventions</th><td width="20%" align="right">&#160;<a accesskey="n" href="conventions-gnu-extns.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="conventions-initialising"></a>Initializing structure members</h2></div></div></div><p>
2    The preferred method of initializing structures is to use
3    designated initialisers, as defined by ISO C99, eg:
4   </p><pre class="programlisting">
5static struct block_device_operations opt_fops = {
6        .open               = opt_open,
7        .release            = opt_release,
8        .ioctl              = opt_ioctl,
9        .check_media_change = opt_media_change,
10};
11   </pre><p>
12    This makes it easy to grep for, and makes it clear which
13    structure fields are set.  You should do this because it looks
14    cool.
15   </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="conventions-borkedcompile.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="conventions.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="conventions-gnu-extns.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Breaking Compilation&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;GNU Extensions</td></tr></table></div></body></html>
16