📄 64bit.html
字号:
The elements<I>f_files</I>,<I>f_ffree</I>,and<I>f_favail</I>of the structure<B>statvfs</B>were changed to the new abstract<B>fsfilcnt_t</B>type.<p>To support the above changes, the following definitions were added to<I>sys/types.h</I> :<dl compact><p><dt><B>blkcnt_t</B><dd>A signed arithmetic type, used for file block counts.<p><dt><B>fsblkcnt_t</B><dd>An arithmetic type, used for filesystem block counts.<p><dt><B>fsfilcnt_t</B><dd>An arithmetic type, used for file serial numbers.<p></dl><p><li><I>sys/time.h</I><p>The<I>tv_usec</I>element of the<B>timeval</B>structure was of type<B>long</B>.This has been changed to use a new abstract data type for signedintegral time values, known as<B>suseconds_t</B>.<B>suseconds_t</B>was added to<I> sys/types.h</I> .<p><li><I>msgrcv()</I><p>In XSH, Issue 4, Version 2,<I>msgrcv()</I>returns the size of the message received as an integer value, butthe size of the message area is specified by a<B>size_t</B>.On 64-bit systems where<B>size_t</B>may be a different data type to<B>int</B>,this will cause problems.XSH, Issue 5 addresses this problem by changing the type of thereturn value from<B>int</B>to<B>ssize_t</B>,and adding a warning to the Description about values of<I>msgsz</I>larger the {SSIZE_MAX}.<p><li><I>sysconf()</I>and<I>unistd.h</I><p>There is now a way to find out the data model supported by the platform.This can be queried at compile time, using the constants defined in<I>unistd.h</I> ,or at run time using the<I>sysconf()</I>function.<p>The following symbolic constants are defined to have the value -1if the implementation never provides the feature, and to havea value other than -1 if the implementation always provides thefeature.If these are undefined, the<I>sysconf()</I>function can be used to determine whether the feature is provided for aparticular invocation of the application.<dl compact><p><dt>_XBS5_ILP32_OFF32<dd>Implementation provides a C-language compilation environment with 32-bit<B>int</B>,<B>long</B>,<B>pointer</B>,and<B>off_t</B>types.<p><dt>_XBS5_ILP32_OFFBIG<dd>Implementation provides a C-language compilation environment with32-bit<B>int</B>,<B>long</B>,and<B>pointer</B>types, and an<B>off_t</B>type using at least 64 bits.<p><dt>_XBS5_LP64_OFF64<dd>Implementation provides a C-language compilation environment with32-bit<B>int</B>and 64-bit<B>long</B>,<B>pointer</B>,and<B>off_t</B>types.<p><dt>_XBS5_LPBIG_OFFBIG<dd>Implementation provides a C-language compilation environment with an<B>int</B>type using at least 32 bits and<B>long</B>,<B>pointer</B>,and<B>off_t</B>types, using at least 64 bits.<p></dl><p></ul><h4>Commands and Utilities, Issue 5 (XCU)</h4><p>A new section of text was added to the end of the first paragraph ofSection 1.9, Utility Description Defaults, to align with requirementsin POSIX.2, and restates that integer variables and constantsused by utilities are permitted to be 64-bit values.<h5>Programming Environments</h5><p>The<I>c89</I>reference page has some new text describing programming environments.All conforming implementations must support one of the followingprogramming environments by default.Applications can use the<I>sysconf()</I>function or the<I>getconf</I>utility to determine which programmingenvironments the implementation supports.<p>The following table describes the supported programming environments.<pre><P><table bordercolor=#000000 border=1 align=center><tr valign=top><th align=center> <b>Programming Environment</b><th align=center> <b>int</b><th align=center> <b>long</b><th align=center> <b>pointer</b><th align=center> <b>off_t</b><tr valign=top><td align=left> XBS5_ILP32_OFF32<td align=left> 32<td align=left> 32<td align=left> 32<td align=left> 32<tr valign=top><td align=left> XBS5_ILP32_OFFBIG<td align=left> 32<td align=left> 32<td align=left> 32<td align=left> >=64<tr valign=top><td align=left> XBS5_LP64_OFF64<td align=left> 32<td align=left> 64<td align=left> 64<td align=left> 64<tr valign=top><td align=left> XBS5_LPBIG_OFFBIG<td align=left> >= 32<td align=left> >= 64<td align=left> >= 64<td align=left> >= 64</table></pre><p>The<I>c89</I>reference page also has text describing new support in<I>getconf</I>and<I>sysconf()</I>to determine configuration strings for C compiler flags,linker/loader flags, and libraries for each supported environment.<p>When an application wishes to use a specific programming environmentrather than an implementation's default programming environmentwhile compiling, the application must first verify that theimplementation supports the desired environment.If the desired programming environment is supported, the applicationcan then invoke<I>c89</I>with the appropriate C compiler flags as thefirst options for the compile, the appropriate linker/loader flagsafter any other options but before any operands, and theappropriate libraries at the end of the operands.<p>The following table shows the various options available:<pre><P><table bordercolor=#000000 border=1 align=center><tr valign=top><th align=center> <b>Programming Environment</b><th align=center> <b>Use</b><th align=center> <b>Compiler Flags</b><tr valign=top><td align=left> XBS5_ILP32_OFF32<td align=left> C Compiler Flags<td align=left> XBS5_ILP32_OFF32_CFLAGS<tr valign=top><td align=left> <td align=left> Linker/Loader Flags<td align=left> XBS5_ILP32_OFF32_LDFLAGS<tr valign=top><td align=left> <td align=left> Libraries Flags<td align=left> XBS5_ILP32_OFF32_LIBS<tr valign=top><td align=left> XBS5_ILP32_OFFBIG<td align=left> C Compiler Flags<td align=left> XBS5_ILP32_OFFBIG_CFLAGS<tr valign=top><td align=left> <td align=left> Linker/Loader Flags<td align=left> XBS5_ILP32_OFFBIG_LDFLAGS<tr valign=top><td align=left> <td align=left> Libraries Flags<td align=left> XBS5_ILP32_OFFBIG_LIBS<tr valign=top><td align=left> XBS5_LP64_OFF64<td align=left> C Compiler Flags<td align=left> XBS5_LP64_OFF64_CFLAG<tr valign=top><td align=left> <td align=left> Linker/Loader Flags<td align=left> XBS5_LP64_OFF64_LDFLAGS<tr valign=top><td align=left> <td align=left> Libraries Flags<td align=left> XBS5_LP64_OFF64_LIBS<tr valign=top><td align=left> XBS5_LPBIG_OFFBIG<td align=left> C Compiler Flags<td align=left> XBS5_LPBIG_OFFBIG_CFLAGS<tr valign=top><td align=left> <td align=left> Linker/Loader Flags<td align=left> XBS5_LPBIG_OFFBIG_LDFLAGS<tr valign=top><td align=left> <td align=left> Libraries Flags<td align=left> XBS5_LPBIG_OFFBIG_LIBS</table></pre><h3>Porting Issues</h3><p>Porting an application to a 64-bit UNIX system can be accomplishedwith a minimal amount of effort if the application was developedusing good modern software engineering practices such as:<ul><p><li>ISO C function prototypes<p><li>consistent and careful use of data types<p><li>all declarations are in headers.<p></ul><p>First of all, determine which data model is available on the platformyou are porting to.The data model you are porting to will have a major impacton the amount of work required to achieve a successful port.<p>Then take the time to create and use ISO C function prototypesif they are absent from the source code.Unfortunately large quantities of perfectly good legacy codedeveloped in the days before portability was a major issuemay not have function prototypes.Fortunately many compilers have an option to generate ISO C functionprototypes.<p>The remainder of this article assumes that you are porting to anLP64 platform since this is the data model of choice amongst majorvendors, but the issues raised are equally valid on some or allof the other 64-bit data models.<h4>General</h4><p>Use utilities such as<I>grep</I>to locate and check all instances of the following:<ul><p><li>Shift and complement operators; that is, "<<", ">>", "~".If used with<B>long</B>,<B>".</B>add "L" to value shifted to avoid an incorrect result.<p><li>Addresses of "&".Make sure they are not being stored in an<B>int</B>.<p><li>Declarations of type<B>long</B>.Many of these can be converted to type<B>int</B>to save space.This is particularly true for network code.<p><li>The functions<I>lseek()</I> ,<I>fseek()</I> ,<I>ftell()</I> ,<I>fgetpos()</I> ,and so on.Use either<B>off_t</B>or<B>fpos_t</B>as appropriate for offset arguments.Do not use<B>int</B>or<B>long</B>to store file offsets.<p><li>All (<B>int *</B>)and (<B>long *</B>)casts.<p><li>Use of (<B>char *</B>)0 for zero or (<B>char *</B>)comparisons.Use NULL instead.<p><li>Hard-coded byte counts or memory sizes.These will be wrong if they assume<B>long</B>sor<B>pointer</B>sare 32 bits.Applications should use the<I>sizeof()</I>operator to avoid such problems.<p></ul><h4>Declarations</h4><p>To enable application code to work on both 32-bit and 64-bit platforms,check all<B>int</B>and<B>long</B>declarations.Declare integer constants using "L" or "U" as appropriate.Ensure an<B>unsigned int</B>is used where appropriate to prevent sign extension.If you have specific variables that need to be 32 bits on bothplatforms, define the type to be<B>int</B>.If the variable should be 32 bits on an ILP32 platform and 64 bits onan LP64 platform, define the variables to be<B>long</B>.<p>Declare numeric variables as<B>int</B>or<B>long</B>for alignment and performance.Don't worry about trying to save bytes by using<B>char</B>or<B>short</B>.Remember that if the type specifier is missing from a declaration,it defaults to an<B>int</B>.Declare character pointers and character bytes as<B>unsigned</B>to avoid sign extension problems with 8-bit characters.<h4>Assignments and Function Parameters</h4><p>All assignments require checking.Since<B>pointer</B>,<B>int</B>,and<B>long</B>are no longer the same size on LP64 platforms, problems may arisedepending on how the variables are assigned and used withinan application.<p>Do not use<B>int</B>and<B>long</B>interchangeably because of the possible truncation of significantdigits, as shown in the following example:<pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -