📄 drivertut6.html
字号:
</td>
<td align="left" valign="top">
<strong>
Alpha 64-Bit Data Size
</strong>
</td>
</tr>
<tr>
<td align="left" valign="top">
short
</td>
<td align="left" valign="top">
16 bits
</td>
<td align="left" valign="top">
16 bits
</td>
</tr>
<tr>
<td align="left" valign="top">
int
</td>
<td align="left" valign="top">
32 bits
</td>
<td align="left" valign="top">
32 bits
</td>
</tr>
<tr>
<td align="left" valign="top">
long
</td>
<td align="left" valign="top">
32 bits
</td>
<td align="left" valign="top">
64 bits
</td>
</tr>
<tr>
<td align="left" valign="top">
* (pointer)
</td>
<td align="left" valign="top">
32 bits
</td>
<td align="left" valign="top">
64 bits
</td>
</tr>
<tr>
<td align="left" valign="top">
long long
</td>
<td align="left" valign="top">
64 bits
</td>
<td align="left" valign="top">
64 bits
</td>
</tr>
<tr>
<td align="left" valign="top">
char
</td>
<td align="left" valign="top">
8 bits
</td>
<td align="left" valign="top">
8 bits
</td>
</tr>
</tbody></table><p>
</p><p>
The following sections describe some common declaration situations:
</p><ul>
<p></p><li>
Declaring 32-bit variables
<p></p></li><li>
Declaring 32-bit and 64-bit variables
<p></p></li><li>
Declaring arguments to C interfaces (functions)
<p></p></li><li>
Declaring register variables
<p></p></li><li>
Performing bit operations on constants
<p></p></li><li>
Using NULL and zero (0) values
<p></p></li><li>
Modifying type
<tt>char</tt>
<p></p></li><li>
Declaring bit fields
<p></p></li><li>
Using
<tt>printf</tt>
formats
<p></p></li><li>
Using
<tt>mb</tt>
and
<tt>wbflush</tt>
<p></p></li><li>
Using the
<tt>volatile</tt>
compiler keyword
</li></ul><p>
</p><blockquote><p align="center"><font size="+1"><strong>Note</strong></font></p><p>
The
<tt>/usr/sys/include/io/common/iotypes.h</tt>
file defines constants used for 64-bit conversions.
See
<cite>Writing Device Drivers: Reference</cite>
for a description of the contents of this file.
</p></blockquote><p>
<a name="Decl32bitSizedVars"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="drivertut6_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="drivertut6_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#CPUandBusIssues"><img src="drivertut6_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#64bitversus32bitIssues"><img src="drivertut6_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#Decl32and64bitSizedVars"><img src="drivertut6_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut7.html"><img src="drivertut6_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="drivertut6_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="drivertut6_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
3.1.5.1牋牋Declaring 32-Bit Variables
</h3>
<p>
<a name="nx_id_134"></a>
Declare any variable that you want to be 32 bits in size as type
<tt>int</tt>,
not type
<tt>long</tt>.
The size of variables declared as type
<tt>int</tt>
is 32 bits on both 32-bit systems
and the 64-bit Alpha systems.
</p><p>
Look at any variables declared as type
<tt>int</tt>
in your existing device drivers to determine if they hold an address.
On Alpha systems,
<tt>sizeof (int)</tt>
is not equal to
<tt>sizeof (char *)</tt>.
</p><p>
In your existing device drivers, also look at any variable declared as
type
<tt>long</tt>.
If it must be 32 bits in size, you
have to change the variable declaration to type
<tt>int</tt>.
<a name="Decl32and64bitSizedVars"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="drivertut6_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="drivertut6_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#CPUandBusIssues"><img src="drivertut6_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#Decl32bitSizedVars"><img src="drivertut6_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#DeclArgstoCFuncs"><img src="drivertut6_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut7.html"><img src="drivertut6_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="drivertut6_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="drivertut6_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
3.1.5.2牋牋Declaring 32-Bit and 64-Bit Variables
</h3>
<p>
<a name="nx_id_135"></a>
If a variable should be 32 bits in size on a 32-bit system and
64 bits in size on a 64-bit Alpha system, declare it as type
<tt>long</tt>.
<a name="DeclArgstoCFuncs"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="drivertut6_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="drivertut6_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#CPUandBusIssues"><img src="drivertut6_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#Decl32and64bitSizedVars"><img src="drivertut6_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#DeclRegVars"><img src="drivertut6_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut7.html"><img src="drivertut6_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="drivertut6_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="drivertut6_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
3.1.5.3牋牋Declaring Arguments to C Functions
</h3>
<p>
<a name="nx_id_136"></a>
Be aware of arguments to C interfaces (functions) where the argument is not
explicitly declared and typed.
You should explicitly declare the
formal parameters to C interfaces; otherwise, their sizes may not match up with the calling program.
The default size is type
<tt>int</tt>,
which truncates 64-bit addresses.
<a name="DeclRegVars"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="drivertut6_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="drivertut6_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#CPUandBusIssues"><img src="drivertut6_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#DeclArgstoCFuncs"><img src="drivertut6_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#PerfBitOperConst"><img src="drivertut6_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut7.html"><img src="drivertut6_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="drivertut6_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="drivertut6_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
3.1.5.4牋牋Declaring Register Variables
</h3>
<p>
<a name="nx_id_137"></a>
When you declare variables with the
<tt>register</tt>
keyword, the compiler defaults its size to that of type
<tt>int</tt>.
For example:
</p><p>
</p><pre>register somevariable;
</pre>
<p>
</p><p>
Remember that these variable declarations also default to type
<tt>int</tt>.
For example:
</p><p>
</p><pre>unsigned somevariable;
</pre>
<p>
Thus, if you want the variable to be 32 bits in size on both 32-bit
systems and 64-bit Alpha systems, the above declarations are
correct.
However, if you want the variable to be 32 bits in size on a 32-bit
system and 64 bits in size on a 64-bit Alpha system,
declare the variables explicitly, using the type
<tt>long</tt>.
<a name="PerfBitOperConst"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="drivertut6_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="drivertut6_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#CPUandBusIssues"><img src="drivertut6_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#DeclRegVars"><img src="drivertut6_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#UsingNullZeroVals"><img src="drivertut6_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut7.html"><img src="drivertut6_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="drivertut6_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="drivertut6_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h3>
3.1.5.5牋牋Performing Bit Operations on Constants
</h3>
<p>
<a name="nx_id_138"></a>
By default, constants are 32-bit quantities.
When you perform shift or bit operations on constants, the compiler
gives 32-bit results.
If you want a 64-bit result, you must follow the constant with an
<tt>L</tt>.
Otherwise, you get a 32-bit result.
For example, the following is a left shift operation that uses the
<tt>L</tt>:
</p><p>
</p><pre>long foo, bar;
foo = 1L << bar;
</pre>
<p>
<a name="UsingNullZeroVals"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="drivertut6_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="drivertut6_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#CPUandBusIssues"><img src="drivertut6_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#PerfBitOperConst"><img src="drivertut6_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -