⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extend.texi

📁 理解和实践操作系统的一本好书
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
#define array(T, N) typeof(T [N])@end smallexample@noindentNow the declaration can be rewritten this way:@smallexamplearray (pointer (char), 4) y;@end smallexample@noindentThus, @code{array (pointer (char), 4)} is the type of arrays of 4pointers to @code{char}.@end itemize@emph{Compatibility Note:} In addition to @code{typeof}, GCC 2 supporteda more limited extension which permitted one to write@smallexampletypedef @var{T} = @var{expr};@end smallexample@noindentwith the effect of declaring @var{T} to have the type of the expression@var{expr}.  This extension does not work with GCC 3 (versions between3.0 and 3.2 will crash; 3.2.1 and later give an error).  Code whichrelies on it should be rewritten to use @code{typeof}:@smallexampletypedef typeof(@var{expr}) @var{T};@end smallexample@noindentThis will work with all versions of GCC@.@node Conditionals@section Conditionals with Omitted Operands@cindex conditional expressions, extensions@cindex omitted middle-operands@cindex middle-operands, omitted@cindex extensions, @code{?:}@cindex @code{?:} extensionsThe middle operand in a conditional expression may be omitted.  Thenif the first operand is nonzero, its value is the value of the conditionalexpression.Therefore, the expression@smallexamplex ? : y@end smallexample@noindenthas the value of @code{x} if that is nonzero; otherwise, the value of@code{y}.This example is perfectly equivalent to@smallexamplex ? x : y@end smallexample@cindex side effect in ?:@cindex ?: side effect@noindentIn this simple case, the ability to omit the middle operand is notespecially useful.  When it becomes useful is when the first operand does,or may (if it is a macro argument), contain a side effect.  Then repeatingthe operand in the middle would perform the side effect twice.  Omittingthe middle operand uses the value already computed without the undesirableeffects of recomputing it.@node Long Long@section Double-Word Integers@cindex @code{long long} data types@cindex double-word arithmetic@cindex multiprecision arithmetic@cindex @code{LL} integer suffix@cindex @code{ULL} integer suffixISO C99 supports data types for integers that are at least 64 bits wide,and as an extension GCC supports them in C89 mode and in C++.Simply write @code{long long int} for a signed integer, or@code{unsigned long long int} for an unsigned integer.  To make aninteger constant of type @code{long long int}, add the suffix @samp{LL}to the integer.  To make an integer constant of type @code{unsigned longlong int}, add the suffix @samp{ULL} to the integer.You can use these types in arithmetic like any other integer types.Addition, subtraction, and bitwise boolean operations on these typesare open-coded on all types of machines.  Multiplication is open-codedif the machine supports fullword-to-doubleword a widening multiplyinstruction.  Division and shifts are open-coded only on machines thatprovide special support.  The operations that are not open-coded usespecial library routines that come with GCC@.There may be pitfalls when you use @code{long long} types for functionarguments, unless you declare function prototypes.  If a functionexpects type @code{int} for its argument, and you pass a value of type@code{long long int}, confusion will result because the caller and thesubroutine will disagree about the number of bytes for the argument.Likewise, if the function expects @code{long long int} and you pass@code{int}.  The best way to avoid such problems is to use prototypes.@node Complex@section Complex Numbers@cindex complex numbers@cindex @code{_Complex} keyword@cindex @code{__complex__} keywordISO C99 supports complex floating data types, and as an extension GCCsupports them in C89 mode and in C++, and supports complex integer datatypes which are not part of ISO C99.  You can declare complex typesusing the keyword @code{_Complex}.  As an extension, the older GNUkeyword @code{__complex__} is also supported.For example, @samp{_Complex double x;} declares @code{x} as avariable whose real part and imaginary part are both of type@code{double}.  @samp{_Complex short int y;} declares @code{y} tohave real and imaginary parts of type @code{short int}; this is notlikely to be useful, but it shows that the set of complex types iscomplete.To write a constant with a complex data type, use the suffix @samp{i} or@samp{j} (either one; they are equivalent).  For example, @code{2.5fi}has type @code{_Complex float} and @code{3i} has type@code{_Complex int}.  Such a constant always has a pure imaginaryvalue, but you can form any complex value you like by adding one to areal constant.  This is a GNU extension; if you have an ISO C99conforming C library (such as GNU libc), and want to construct complexconstants of floating type, you should include @code{<complex.h>} anduse the macros @code{I} or @code{_Complex_I} instead.@cindex @code{__real__} keyword@cindex @code{__imag__} keywordTo extract the real part of a complex-valued expression @var{exp}, write@code{__real__ @var{exp}}.  Likewise, use @code{__imag__} toextract the imaginary part.  This is a GNU extension; for values offloating type, you should use the ISO C99 functions @code{crealf},@code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and@code{cimagl}, declared in @code{<complex.h>} and also provided asbuilt-in functions by GCC@.@cindex complex conjugationThe operator @samp{~} performs complex conjugation when used on a valuewith a complex type.  This is a GNU extension; for values offloating type, you should use the ISO C99 functions @code{conjf},@code{conj} and @code{conjl}, declared in @code{<complex.h>} and alsoprovided as built-in functions by GCC@.GCC can allocate complex automatic variables in a noncontiguousfashion; it's even possible for the real part to be in a register whilethe imaginary part is on the stack (or vice-versa).  Only the DWARF2debug info format can represent this, so use of DWARF2 is recommended.If you are using the stabs debug info format, GCC describes a noncontiguouscomplex variable as if it were two separate variables of noncomplex type.If the variable's actual name is @code{foo}, the two fictitiousvariables are named @code{foo$real} and @code{foo$imag}.  You canexamine and set these two fictitious variables with your debugger.@node Floating Types@section Additional Floating Types@cindex additional floating types@cindex @code{__float80} data type@cindex @code{__float128} data type@cindex @code{w} floating point suffix@cindex @code{q} floating point suffix@cindex @code{W} floating point suffix@cindex @code{Q} floating point suffixAs an extension, the GNU C compiler supports additional floatingtypes, @code{__float80} and @code{__float128} to support 80bit(@code{XFmode}) and 128 bit (@code{TFmode}) floating types.Support for additional types includes the arithmetic operators:add, subtract, multiply, divide; unary arithmetic operators;relational operators; equality operators; and conversions to and frominteger and other floating types.  Use a suffix @samp{w} or @samp{W}in a literal constant of type @code{__float80} and @samp{q} or @samp{Q}for @code{_float128}.  You can declare complex types using thecorresponding internal complex type, @code{XCmode} for @code{__float80}type and @code{TCmode} for @code{__float128} type:@smallexampletypedef _Complex float __attribute__((mode(TC))) _Complex128;typedef _Complex float __attribute__((mode(XC))) _Complex80;@end smallexampleNot all targets support additional floating point types.  @code{__float80}is supported on i386, x86_64 and ia64 targets and target @code{__float128}is supported on x86_64 and ia64 targets.@node Decimal Float@section Decimal Floating Types@cindex decimal floating types@cindex @code{_Decimal32} data type@cindex @code{_Decimal64} data type@cindex @code{_Decimal128} data type@cindex @code{df} integer suffix@cindex @code{dd} integer suffix@cindex @code{dl} integer suffix@cindex @code{DF} integer suffix@cindex @code{DD} integer suffix@cindex @code{DL} integer suffixAs an extension, the GNU C compiler supports decimal floating types asdefined in the N1176 draft of ISO/IEC WDTR24732.  Support for decimalfloating types in GCC will evolve as the draft technical report changes.Calling conventions for any target might also change.  Not all targetssupport decimal floating types.The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and@code{_Decimal128}.  They use a radix of ten, unlike the floating types@code{float}, @code{double}, and @code{long double} whose radix is notspecified by the C standard but is usually two.Support for decimal floating types includes the arithmetic operatorsadd, subtract, multiply, divide; unary arithmetic operators;relational operators; equality operators; and conversions to and frominteger and other floating types.  Use a suffix @samp{df} or@samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for@code{_Decimal128}.GCC support of decimal float as specified by the draft technical reportis incomplete:@itemize @bullet@itemTranslation time data type (TTDT) is not supported.@itemWhen the value of a decimal floating type cannot be represented in theinteger type to which it is being converted, the result is undefinedrather than the result value specified by the draft technical report.@end itemizeTypes @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}are supported by the DWARF2 debug information format.@node Hex Floats@section Hex Floats@cindex hex floatsISO C99 supports floating-point numbers written not only in the usualdecimal notation, such as @code{1.55e1}, but also numbers such as@code{0x1.fp3} written in hexadecimal format.  As a GNU extension, GCCsupports this in C89 mode (except in some cases when strictlyconforming) and in C++.  In that format the@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field aremandatory.  The exponent is a decimal number that indicates the power of2 by which the significant part will be multiplied.  Thus @samp{0x1.f} is@tex$1 {15\over16}$,@end tex@ifnottex1 15/16,@end ifnottex@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}is the same as @code{1.55e1}.Unlike for floating-point numbers in the decimal notation the exponentis always required in the hexadecimal notation.  Otherwise the compilerwould not be able to resolve the ambiguity of, e.g., @code{0x1.f}.  Thiscould mean @code{1.0f} or @code{1.9375} since @samp{f} is also theextension for floating-point constants of type @code{float}.@node Fixed-Point@section Fixed-Point Types@cindex fixed-point types@cindex @code{_Fract} data type@cindex @code{_Accum} data type@cindex @code{_Sat} data type@cindex @code{hr} fixed-suffix@cindex @code{r} fixed-suffix@cindex @code{lr} fixed-suffix@cindex @code{llr} fixed-suffix@cindex @code{uhr} fixed-suffix@cindex @code{ur} fixed-suffix@cindex @code{ulr} fixed-suffix@cindex @code{ullr} fixed-suffix@cindex @code{hk} fixed-suffix@cindex @code{k} fixed-suffix@cindex @code{lk} fixed-suffix@cindex @code{llk} fixed-suffix@cindex @code{uhk} fixed-suffix@cindex @code{uk} fixed-suffix@cindex @code{ulk} fixed-suffix@cindex @code{ullk} fixed-suffix@cindex @code{HR} fixed-suffix@cindex @code{R} fixed-suffix@cindex @code{LR} fixed-suffix@cindex @code{LLR} fixed-suffix@cindex @code{UHR} fixed-suffix@cindex @code{UR} fixed-suffix@cindex @code{ULR} fixed-suffix@cindex @code{ULLR} fixed-suffix@cindex @code{HK} fixed-suffix@cindex @code{K} fixed-suffix@cindex @code{LK} fixed-suffix@cindex @code{LLK} fixed-suffix@cindex @code{UHK} fixed-suffix@cindex @code{UK} fixed-suffix@cindex @code{ULK} fixed-suffix@cindex @code{ULLK} fixed-suffixAs an extension, the GNU C compiler supports fixed-point types asdefined in the N1169 draft of ISO/IEC DTR 18037.  Support for fixed-pointtypes in GCC will evolve as the draft technical report changes.Calling conventions for any target might also change.  Not all targetssupport fixed-point types.The fixed-point types are@code{short _Fract},@code{_Fract},@code{long _Fract},@code{long long _Fract},@code{unsigned short _Fract},@code{unsigned _Fract},@code{unsigned long _Fract},@code{unsigned long long _Fract},@code{_Sat short _Fract},@code{_Sat _Fract},@code{_Sat long _Fract},@code{_Sat long long _Fract},@code{_Sat unsigned short _Fract},@code{_Sat unsigned _Fract},@code{_Sat unsigned long _Fract},@code{_Sat unsigned long long _Fract},@code{short _Accum},@code{_Accum},@code{long _Accum},@code{long long _Accum},@code{unsigned short _Accum},@code{unsigned _Accum},@code{unsigned long _Accum},@code{unsigned long long _Accum},@code{_Sat short _Accum},@code{_Sat _Accum},@code{_Sat long _Accum},@code{_Sat long long _Accum},@code{_Sat unsigned short _Accum},@code{_Sat unsigned _Accum},@code{_Sat unsigned long _Accum},@code{_Sat unsigned long long _Accum}.Fixed-point data values contain fractional and optional integral parts.The format of fixed-point data varies and depends on the target machine.Support for fixed-point types includes prefix and postfix incrementand decrement operators (@code{++}, @code{--}); unary arithmetic operators(@code{+}, @code{-}, @code{!}); binary arithmetic operators (@code{+},@code{-}, @code{*}, @code{/}); binary shift operators (@code{<<}, @code{>>});relational operators (@code{<}, @code{<=}, @code{>=}, @code{>});equality operators (@code{==}, @code{!=}); assignment operators(@code{+=}, @code{-=}, @code{*=}, @code{/=}, @code{<<=}, @code{>>=});and conversions to and from integer, floating-point, or fixed-point types.Use a suffix @samp{hr} or @samp{HR} in a literal constant of type@code{short _Fract} and @code{_Sat short _Fract},@samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract},@samp{lr} or @samp{LR} for @code{long _Fract} and @code{_Sat long _Fract},@samp{llr} or @samp{LLR} for @code{long long _Fract} and@code{_Sat long long _Fract},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -