<title>Idioms</title>
<head>
<script language="JavaScript">
</script>
</head>
<body bgcolor="#ffffcc">
<hr>
<center>
<h1>Idioms</h1>
</center>
<hr>
<p>

Here are some C idioms that may be usefull.

<p><hr align=center width="50%"><p>
Place <code>\0</code> at the location pointed to by <code>ptr</code>
then increment <code>ptr</code>
<p>
<center>
<table border=2 bgcolor=ivory>
<tr><td>
<pre>

   *ptr++ = '\0';   
</pre>
</td></tr>
</table>
</center>

<p><hr align=center width="50%"><p>
Increment <code>ptr</code> then 
place <code>\0</code> at the location pointed to by <code>ptr</code>
<p>
<center>
<table border=2 bgcolor=ivory>
<tr><td>
<pre>

   *++ptr = '\0';   
</pre>
</td></tr>
</table>
</center>

<p><hr align=center width="50%"><p>
This program will print its self! I guess its not of any real
use, but I think its clever.
<p>
<center>
<table border=2 bgcolor=ivory>
<tr><td>
<pre>

  main(a) {a="main(a) {a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}  
</pre>
</td></tr>
</table>
</center>

<p><hr align=center width="50%"><p>
This is something I saw out on the web. It swaps the value of two
variables without
using a third variable as a temporary store. 
<p>
<center>
<table border=2 bgcolor=ivory>
<tr><td>
<pre>

   one ^= two;   
   two ^= one;
   one ^= two;
</pre>
</td></tr>
</table>
</center>

<a name=printf>
<p><hr align=center width="50%"><p>

Have you ever had a SEGV from <a href="../FUNCTIONS/printf.html">printf</a>
because you passed a NULL pointer to a %s flag???. This idiom will put
a stop to all that nonsence.
<p>
<center>
<table border=2 bgcolor=ivory>
<tr><td>
<pre>

   printf("%s\n", Str ? Str : "Null");   
</pre>
</td></tr>
</table>
</center>



<p><hr align=center width="50%"><p>
<p>
<img src="../../GRAPHICS/computer.gif" alt="o">
<a href=../EXAMPLES/swap.c>Program swapping the contents of two variables</a>.
<p>

<hr>
<h2>See Also:</h2>

<img src="../../GRAPHICS/whiteball.gif" alt="o">
<a href="got_ya.html">Common Coding Errors</a>.<p>


<p>

<hr>
<p>
<center>
<table border=2 width="80%" bgcolor="ivory">
<tr align=center>
<td width="25%">
<a href="../cref.html">                  Top</a>
</td><td width="25%">
<a href="../master_index.html">          Master Index</a>
</td><td width="25%">
<a href="keywords.html">                 Keywords</a>
</td><td width="25%">
<a href="../FUNCTIONS/funcref.htm">      Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address>Martin Leslie 
</address><p>
</body>
</html>
'>
<input type='hidden' name='id' value='0e1929dedea36781e25902118c93edd8d8f09af1'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/commit/?id=0e1929dedea36781e25902118c93edd8d8f09af1'>root</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools?id=0e1929dedea36781e25902118c93edd8d8f09af1'>tools</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing?id=0e1929dedea36781e25902118c93edd8d8f09af1'>testing</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests?id=0e1929dedea36781e25902118c93edd8d8f09af1'>selftests</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/ftrace?id=0e1929dedea36781e25902118c93edd8d8f09af1'>ftrace</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/ftrace/test.d?id=0e1929dedea36781e25902118c93edd8d8f09af1'>test.d</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/ftrace/test.d/functions?id=0e1929dedea36781e25902118c93edd8d8f09af1'>functions</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='0e1929dedea36781e25902118c93edd8d8f09af1'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>Mike Looijmans &lt;mike.looijmans@topic.nl&gt;</td><td class='right'>2017-01-16 15:49:38 +0100</td></tr>
<tr><th>committer</th><td>Wolfram Sang &lt;wsa@the-dreams.de&gt;</td><td class='right'>2017-01-25 22:07:40 +0100</td></tr>
<tr><th>commit</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/ftrace/test.d/functions?id=0e1929dedea36781e25902118c93edd8d8f09af1'>0e1929dedea36781e25902118c93edd8d8f09af1</a> (<a href='/cgit.cgi/linux/net-next.git/patch/tools/testing/selftests/ftrace/test.d/functions?id=0e1929dedea36781e25902118c93edd8d8f09af1'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/tree/?id=0e1929dedea36781e25902118c93edd8d8f09af1'>5e353f42c88f892c20528b8a4c28856919594944</a> /<a href='/cgit.cgi/linux/net-next.git/tree/tools/testing/selftests/ftrace/test.d/functions?id=0e1929dedea36781e25902118c93edd8d8f09af1'>tools/testing/selftests/ftrace/test.d/functions</a></td></tr>
<tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/ftrace/test.d/functions?id=7a308bb3016f57e5be11a677d15b821536419d36'>7a308bb3016f57e5be11a677d15b821536419d36</a> (<a href='/cgit.cgi/linux/net-next.git/diff/tools/testing/selftests/ftrace/test.d/functions?id=0e1929dedea36781e25902118c93edd8d8f09af1&amp;id2=7a308bb3016f57e5be11a677d15b821536419d36'>diff</a>)</td></tr></table>
<div class='commit-subject'>i2c: i2c-cadence: Initialize configuration before probing devices</div><div class='commit-msg'>The cadence I2C driver calls cdns_i2c_writereg(..) to setup a workaround
in the controller, but did so after calling i2c_add_adapter() which starts
probing devices on the bus. Change the order so that the configuration is
completely finished before using the adapter.

Signed-off-by: Mike Looijmans &lt;mike.looijmans@topic.nl&gt;
Signed-off-by: Wolfram Sang &lt;wsa@the-dreams.de&gt;
</div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?id=0e1929dedea36781e25902118c93edd8d8f09af1'>Diffstat</a> (limited to 'tools/testing/selftests/ftrace/test.d/functions')</div><table summary='diffstat' class='diffstat'>