linux/Documentation/sparse.txt
<<
>>
Prefs
   1Copyright 2004 Linus Torvalds
   2Copyright 2004 Pavel Machek <pavel@ucw.cz>
   3Copyright 2006 Bob Copeland <me@bobcopeland.com>
   4
   5Using sparse for typechecking
   6~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   7
   8"__bitwise" is a type attribute, so you have to do something like this:
   9
  10        typedef int __bitwise pm_request_t;
  11
  12        enum pm_request {
  13                PM_SUSPEND = (__force pm_request_t) 1,
  14                PM_RESUME = (__force pm_request_t) 2
  15        };
  16
  17which makes PM_SUSPEND and PM_RESUME "bitwise" integers (the "__force" is
  18there because sparse will complain about casting to/from a bitwise type,
  19but in this case we really _do_ want to force the conversion). And because
  20the enum values are all the same type, now "enum pm_request" will be that
  21type too.
  22
  23And with gcc, all the __bitwise/__force stuff goes away, and it all ends
  24up looking just like integers to gcc.
  25
  26Quite frankly, you don't need the enum there. The above all really just
  27boils down to one special "int __bitwise" type.
  28
  29So the simpler way is to just do
  30
  31        typedef int __bitwise pm_request_t;
  32
  33        #define PM_SUSPEND ((__force pm_request_t) 1)
  34        #define PM_RESUME ((__force pm_request_t) 2)
  35
  36and you now have all the infrastructure needed for strict typechecking.
  37
  38One small note: the constant integer "0" is special. You can use a
  39constant zero as a bitwise integer type without sparse ever complaining.
  40This is because "bitwise" (as the name implies) was designed for making
  41sure that bitwise types don't get mixed up (little-endian vs big-endian
  42vs cpu-endian vs whatever), and there the constant "0" really _is_
  43special.
  44
  45__bitwise__ - to be used for relatively compact stuff (gfp_t, etc.n26
  lass="lin1h2"Docuarse.tx4#L36"L40most5  nerne"d/a>consta__CHECK_namIAN__3" class="line" name="L43">  43spe7
  4use a
be*="linL41".  Wine" nam4" id="L4" class="line" name="L4">   ning.
">  19  43sp5aking
  5ndian
  5 _is_
  5cial.
  5 4
  526
  lass="lin1h2"Docua5se.tx5#L36"onstant   415">e" nL45ea" na case ws use sSt zerohomepagL8"> id="L35" class="line" name="L35">  5king.
  57
  5use a
  455">e" nd" nlops="la case w"L5">   5Using sparse for typechening.
  43sp6aking
  6ndian
  6 _is_
  6cial.
gi 19reealvailablL8">.3" class="line" name="L43">  43sp6 4
<6a href="Documentation/s6se.tx6#L35" id="L35" class="line" name="L35">  6ecking
http:/nwww.codemonkey.org.uk/projectsngi -snapshotsname="LnL35" id="L35" class="line" name="L35">  6king.
  67
  6use a
  29So the simpler way is to j7ning.
  7aking
  7ndian
  7cial.
  43sp7 4
<7a href="Documentation/s7se.tx7#L35" id="L35" class="line" name="L35">  7ecking
<7a href="Documentation/s7se.tx76xt#L5" id="L5" c id="L35" class="line" name="L35">  7~~~~~~
  77
  7use a
   ning.
__   d, orne" " whate17" cC=2ls down o runsnt zeroon"" na    s"whe">  "" ny"L26"> 9">  29So the simpler way is to j8aking
rec>__   d ornno".  T/a>5">tere" namfas" ="l19  29So the simpler way is to j8ndian
  43sp8 _is_
  8cial.
  8 4
<8a href="Documentation/s8se.tx85L19" iild system/p"Do s"-Wclass="linaame="L automntat nam1  T  8ecking
<8a href="Documentation/s8se.tx86xt#Lcthe sss="lim"l1 class=__CHECK_namIAN__ute, so you have to do something like8~~~~~~
<8a href="Documentation/s8se.tx8txt#L7" id="L7" class="line" name="L7">    7
   use a
  9ning.
T  43sp9aking


results" clasf="Docufooter">
 iroorigital1LXR softw"linby"" naid="L35" http:/ns;_rcerefge.net/projectsnlxr">LXR c>_munityL27",19" clexperi namela case wnby"id="L35" mailto:lxr@ lxr@ 
lxr. Red_  lss="pro ASL27",1providereofss="lx>vs cult id=ll topernee ws " rvic s"" iceo1995.
results" /bodyts /htmlm>