Revert wrong checkin
[official-gcc.git] / gcc / doc / implement-c.texi
blob4b9afaa69396715d88cc706a1e77e674e66ff108
1 @c Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008
2 @c Free Software Foundation, Inc.
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
6 @node C Implementation
7 @chapter C Implementation-defined behavior
8 @cindex implementation-defined behavior, C language
10 A conforming implementation of ISO C is required to document its
11 choice of behavior in each of the areas that are designated
12 ``implementation defined''.  The following lists all such areas,
13 along with the section numbers from the ISO/IEC 9899:1990 and ISO/IEC
14 9899:1999 standards.  Some areas are only implementation-defined in
15 one version of the standard.
17 Some choices depend on the externally determined ABI for the platform
18 (including standard character encodings) which GCC follows; these are
19 listed as ``determined by ABI'' below.  @xref{Compatibility, , Binary
20 Compatibility}, and @uref{http://gcc.gnu.org/readings.html}.  Some
21 choices are documented in the preprocessor manual.
22 @xref{Implementation-defined behavior, , Implementation-defined
23 behavior, cpp, The C Preprocessor}.  Some choices are made by the
24 library and operating system (or other environment when compiling for
25 a freestanding environment); refer to their documentation for details.
27 @menu
28 * Translation implementation::
29 * Environment implementation::
30 * Identifiers implementation::
31 * Characters implementation::
32 * Integers implementation::
33 * Floating point implementation::
34 * Arrays and pointers implementation::
35 * Hints implementation::
36 * Structures unions enumerations and bit-fields implementation::
37 * Qualifiers implementation::
38 * Declarators implementation::
39 * Statements implementation::
40 * Preprocessing directives implementation::
41 * Library functions implementation::
42 * Architecture implementation::
43 * Locale-specific behavior implementation::
44 @end menu
46 @node Translation implementation
47 @section Translation
49 @itemize @bullet
50 @item
51 @cite{How a diagnostic is identified (C90 3.7, C99 3.10, C90 and C99 5.1.1.3).}
53 Diagnostics consist of all the output sent to stderr by GCC@.
55 @item
56 @cite{Whether each nonempty sequence of white-space characters other than
57 new-line is retained or replaced by one space character in translation
58 phase 3 (C90 and C99 5.1.1.2).}
60 @xref{Implementation-defined behavior, , Implementation-defined
61 behavior, cpp, The C Preprocessor}.
63 @end itemize
65 @node Environment implementation
66 @section Environment
68 The behavior of most of these points are dependent on the implementation
69 of the C library, and are not defined by GCC itself.
71 @itemize @bullet
72 @item
73 @cite{The mapping between physical source file multibyte characters
74 and the source character set in translation phase 1 (C90 and C99 5.1.1.2).}
76 @xref{Implementation-defined behavior, , Implementation-defined
77 behavior, cpp, The C Preprocessor}.
79 @end itemize
81 @node Identifiers implementation
82 @section Identifiers
84 @itemize @bullet
85 @item
86 @cite{Which additional multibyte characters may appear in identifiers
87 and their correspondence to universal character names (C99 6.4.2).}
89 @xref{Implementation-defined behavior, , Implementation-defined
90 behavior, cpp, The C Preprocessor}.
92 @item
93 @cite{The number of significant initial characters in an identifier
94 (C90 6.1.2, C90 and C99 5.2.4.1, C99 6.4.2).}
96 For internal names, all characters are significant.  For external names,
97 the number of significant characters are defined by the linker; for
98 almost all targets, all characters are significant.
100 @item
101 @cite{Whether case distinctions are significant in an identifier with
102 external linkage (C90 6.1.2).}
104 This is a property of the linker.  C99 requires that case distinctions
105 are always significant in identifiers with external linkage and
106 systems without this property are not supported by GCC@.
108 @end itemize
110 @node Characters implementation
111 @section Characters
113 @itemize @bullet
114 @item
115 @cite{The number of bits in a byte (C90 3.4, C99 3.6).}
117 Determined by ABI@.
119 @item
120 @cite{The values of the members of the execution character set (C90
121 and C99 5.2.1).}
123 Determined by ABI@.
125 @item
126 @cite{The unique value of the member of the execution character set produced
127 for each of the standard alphabetic escape sequences (C90 and C99 5.2.2).}
129 Determined by ABI@.
131 @item
132 @cite{The value of a @code{char} object into which has been stored any
133 character other than a member of the basic execution character set
134 (C90 6.1.2.5, C99 6.2.5).}
136 Determined by ABI@.
138 @item
139 @cite{Which of @code{signed char} or @code{unsigned char} has the same
140 range, representation, and behavior as ``plain'' @code{char} (C90
141 6.1.2.5, C90 6.2.1.1, C99 6.2.5, C99 6.3.1.1).}
143 @opindex fsigned-char
144 @opindex funsigned-char
145 Determined by ABI@.  The options @option{-funsigned-char} and
146 @option{-fsigned-char} change the default.  @xref{C Dialect Options, ,
147 Options Controlling C Dialect}.
149 @item
150 @cite{The mapping of members of the source character set (in character
151 constants and string literals) to members of the execution character
152 set (C90 6.1.3.4, C99 6.4.4.4, C90 and C99 5.1.1.2).}
154 Determined by ABI@.
156 @item
157 @cite{The value of an integer character constant containing more than one
158 character or containing a character or escape sequence that does not map
159 to a single-byte execution character (C90 6.1.3.4, C99 6.4.4.4).}
161 @xref{Implementation-defined behavior, , Implementation-defined
162 behavior, cpp, The C Preprocessor}.
164 @item
165 @cite{The value of a wide character constant containing more than one
166 multibyte character, or containing a multibyte character or escape
167 sequence not represented in the extended execution character set (C90
168 6.1.3.4, C99 6.4.4.4).}
170 @xref{Implementation-defined behavior, , Implementation-defined
171 behavior, cpp, The C Preprocessor}.
173 @item
174 @cite{The current locale used to convert a wide character constant consisting
175 of a single multibyte character that maps to a member of the extended
176 execution character set into a corresponding wide character code (C90
177 6.1.3.4, C99 6.4.4.4).}
179 @xref{Implementation-defined behavior, , Implementation-defined
180 behavior, cpp, The C Preprocessor}.
182 @item
183 @cite{The current locale used to convert a wide string literal into
184 corresponding wide character codes (C90 6.1.4, C99 6.4.5).}
186 @xref{Implementation-defined behavior, , Implementation-defined
187 behavior, cpp, The C Preprocessor}.
189 @item
190 @cite{The value of a string literal containing a multibyte character or escape
191 sequence not represented in the execution character set (C90 6.1.4, C99 6.4.5).}
193 @xref{Implementation-defined behavior, , Implementation-defined
194 behavior, cpp, The C Preprocessor}.
195 @end itemize
197 @node Integers implementation
198 @section Integers
200 @itemize @bullet
201 @item
202 @cite{Any extended integer types that exist in the implementation (C99 6.2.5).}
204 GCC does not support any extended integer types.
205 @c The __mode__ attribute might create types of precisions not
206 @c otherwise supported, but the syntax isn't right for use everywhere
207 @c the standard type names might be used.  Predefined typedefs should
208 @c be used if any extended integer types are to be defined.  The
209 @c __int128_t and __uint128_t typedefs are not extended integer types
210 @c as they are generally longer than the ABI-specified intmax_t.
212 @item
213 @cite{Whether signed integer types are represented using sign and magnitude,
214 two's complement, or one's complement, and whether the extraordinary value
215 is a trap representation or an ordinary value (C99 6.2.6.2).}
217 GCC supports only two's complement integer types, and all bit patterns
218 are ordinary values.
220 @item
221 @cite{The rank of any extended integer type relative to another extended
222 integer type with the same precision (C99 6.3.1.1).}
224 GCC does not support any extended integer types.
225 @c If it did, there would only be one of each precision and signedness.
227 @item
228 @cite{The result of, or the signal raised by, converting an integer to a
229 signed integer type when the value cannot be represented in an object of
230 that type (C90 6.2.1.2, C99 6.3.1.3).}
232 For conversion to a type of width @math{N}, the value is reduced
233 modulo @math{2^N} to be within range of the type; no signal is raised.
235 @item
236 @cite{The results of some bitwise operations on signed integers (C90
237 6.3, C99 6.5).}
239 Bitwise operators act on the representation of the value including
240 both the sign and value bits, where the sign bit is considered
241 immediately above the highest-value value bit.  Signed @samp{>>} acts
242 on negative numbers by sign extension.
244 GCC does not use the latitude given in C99 only to treat certain
245 aspects of signed @samp{<<} as undefined, but this is subject to
246 change.
248 @item
249 @cite{The sign of the remainder on integer division (C90 6.3.5).}
251 GCC always follows the C99 requirement that the result of division is
252 truncated towards zero.
254 @end itemize
256 @node Floating point implementation
257 @section Floating point
259 @itemize @bullet
260 @item
261 @cite{The accuracy of the floating-point operations and of the library
262 functions in @code{<math.h>} and @code{<complex.h>} that return floating-point
263 results (C90 and C99 5.2.4.2.2).}
265 The accuracy is unknown.
267 @item
268 @cite{The rounding behaviors characterized by non-standard values
269 of @code{FLT_ROUNDS} @gol
270 (C90 and C99 5.2.4.2.2).}
272 GCC does not use such values.
274 @item
275 @cite{The evaluation methods characterized by non-standard negative
276 values of @code{FLT_EVAL_METHOD} (C99 5.2.4.2.2).}
278 GCC does not use such values.
280 @item
281 @cite{The direction of rounding when an integer is converted to a
282 floating-point number that cannot exactly represent the original
283 value (C90 6.2.1.3, C99 6.3.1.4).}
285 C99 Annex F is followed.
287 @item
288 @cite{The direction of rounding when a floating-point number is
289 converted to a narrower floating-point number (C90 6.2.1.4, C99
290 6.3.1.5).}
292 C99 Annex F is followed.
294 @item
295 @cite{How the nearest representable value or the larger or smaller
296 representable value immediately adjacent to the nearest representable
297 value is chosen for certain floating constants (C90 6.1.3.1, C99
298 6.4.4.2).}
300 C99 Annex F is followed.
302 @item
303 @cite{Whether and how floating expressions are contracted when not
304 disallowed by the @code{FP_CONTRACT} pragma (C99 6.5).}
306 Expressions are currently only contracted if
307 @option{-funsafe-math-optimizations} or @option{-ffast-math} are used.
308 This is subject to change.
310 @item
311 @cite{The default state for the @code{FENV_ACCESS} pragma (C99 7.6.1).}
313 This pragma is not implemented, but the default is to ``off'' unless
314 @option{-frounding-math} is used in which case it is ``on''.
316 @item
317 @cite{Additional floating-point exceptions, rounding modes, environments,
318 and classifications, and their macro names (C99 7.6, C99 7.12).}
320 This is dependent on the implementation of the C library, and is not
321 defined by GCC itself.
323 @item
324 @cite{The default state for the @code{FP_CONTRACT} pragma (C99 7.12.2).}
326 This pragma is not implemented.  Expressions are currently only
327 contracted if @option{-funsafe-math-optimizations} or
328 @option{-ffast-math} are used.  This is subject to change.
330 @item
331 @cite{Whether the ``inexact'' floating-point exception can be raised
332 when the rounded result actually does equal the mathematical result
333 in an IEC 60559 conformant implementation (C99 F.9).}
335 This is dependent on the implementation of the C library, and is not
336 defined by GCC itself.
338 @item
339 @cite{Whether the ``underflow'' (and ``inexact'') floating-point
340 exception can be raised when a result is tiny but not inexact in an
341 IEC 60559 conformant implementation (C99 F.9).}
343 This is dependent on the implementation of the C library, and is not
344 defined by GCC itself.
346 @end itemize
348 @node Arrays and pointers implementation
349 @section Arrays and pointers
351 @itemize @bullet
352 @item
353 @cite{The result of converting a pointer to an integer or
354 vice versa (C90 6.3.4, C99 6.3.2.3).}
356 A cast from pointer to integer discards most-significant bits if the
357 pointer representation is larger than the integer type,
358 sign-extends@footnote{Future versions of GCC may zero-extend, or use
359 a target-defined @code{ptr_extend} pattern.  Do not rely on sign extension.}
360 if the pointer representation is smaller than the integer type, otherwise
361 the bits are unchanged.
362 @c ??? We've always claimed that pointers were unsigned entities.
363 @c Shouldn't we therefore be doing zero-extension?  If so, the bug
364 @c is in convert_to_integer, where we call type_for_size and request
365 @c a signed integral type.  On the other hand, it might be most useful
366 @c for the target if we extend according to POINTERS_EXTEND_UNSIGNED.
368 A cast from integer to pointer discards most-significant bits if the
369 pointer representation is smaller than the integer type, extends according
370 to the signedness of the integer type if the pointer representation
371 is larger than the integer type, otherwise the bits are unchanged.
373 When casting from pointer to integer and back again, the resulting
374 pointer must reference the same object as the original pointer, otherwise
375 the behavior is undefined.  That is, one may not use integer arithmetic to
376 avoid the undefined behavior of pointer arithmetic as proscribed in
377 C99 6.5.6/8.
379 @item
380 @cite{The size of the result of subtracting two pointers to elements
381 of the same array (C90 6.3.6, C99 6.5.6).}
383 The value is as specified in the standard and the type is determined
384 by the ABI@.
386 @end itemize
388 @node Hints implementation
389 @section Hints
391 @itemize @bullet
392 @item
393 @cite{The extent to which suggestions made by using the @code{register}
394 storage-class specifier are effective (C90 6.5.1, C99 6.7.1).}
396 The @code{register} specifier affects code generation only in these ways:
398 @itemize @bullet
399 @item
400 When used as part of the register variable extension, see
401 @ref{Explicit Reg Vars}.
403 @item
404 When @option{-O0} is in use, the compiler allocates distinct stack
405 memory for all variables that do not have the @code{register}
406 storage-class specifier; if @code{register} is specified, the variable
407 may have a shorter lifespan than the code would indicate and may never
408 be placed in memory.
410 @item
411 On some rare x86 targets, @code{setjmp} doesn't save the registers in
412 all circumstances.  In those cases, GCC doesn't allocate any variables
413 in registers unless they are marked @code{register}.
415 @end itemize
417 @item
418 @cite{The extent to which suggestions made by using the inline function
419 specifier are effective (C99 6.7.4).}
421 GCC will not inline any functions if the @option{-fno-inline} option is
422 used or if @option{-O0} is used.  Otherwise, GCC may still be unable to
423 inline a function for many reasons; the @option{-Winline} option may be
424 used to determine if a function has not been inlined and why not.
426 @end itemize
428 @node Structures unions enumerations and bit-fields implementation
429 @section Structures, unions, enumerations, and bit-fields
431 @itemize @bullet
432 @item
433 @cite{A member of a union object is accessed using a member of a
434 different type (C90 6.3.2.3).}
436 The relevant bytes of the representation of the object are treated as
437 an object of the type used for the access.  @xref{Type-punning}.  This
438 may be a trap representation.
440 @item
441 @cite{Whether a ``plain'' @code{int} bit-field is treated as a
442 @code{signed int} bit-field or as an @code{unsigned int} bit-field
443 (C90 6.5.2, C90 6.5.2.1, C99 6.7.2, C99 6.7.2.1).}
445 @opindex funsigned-bitfields
446 By default it is treated as @code{signed int} but this may be changed
447 by the @option{-funsigned-bitfields} option.
449 @item
450 @cite{Allowable bit-field types other than @code{_Bool}, @code{signed int},
451 and @code{unsigned int} (C99 6.7.2.1).}
453 No other types are permitted in strictly conforming mode.
454 @c Would it be better to restrict the pedwarn for other types to C90
455 @c mode and document the other types for C99 mode?
457 @item
458 @cite{Whether a bit-field can straddle a storage-unit boundary (C90
459 6.5.2.1, C99 6.7.2.1).}
461 Determined by ABI@.
463 @item
464 @cite{The order of allocation of bit-fields within a unit (C90
465 6.5.2.1, C99 6.7.2.1).}
467 Determined by ABI@.
469 @item
470 @cite{The alignment of non-bit-field members of structures (C90
471 6.5.2.1, C99 6.7.2.1).}
473 Determined by ABI@.
475 @item
476 @cite{The integer type compatible with each enumerated type (C90
477 6.5.2.2, C99 6.7.2.2).}
479 @opindex fshort-enums
480 Normally, the type is @code{unsigned int} if there are no negative
481 values in the enumeration, otherwise @code{int}.  If
482 @option{-fshort-enums} is specified, then if there are negative values
483 it is the first of @code{signed char}, @code{short} and @code{int}
484 that can represent all the values, otherwise it is the first of
485 @code{unsigned char}, @code{unsigned short} and @code{unsigned int}
486 that can represent all the values.
487 @c On a few unusual targets with 64-bit int, this doesn't agree with
488 @c the code and one of the types accessed via mode attributes (which
489 @c are not currently considered extended integer types) may be used.
490 @c If these types are made extended integer types, it would still be
491 @c the case that -fshort-enums stops the implementation from
492 @c conforming to C90 on those targets.
494 On some targets, @option{-fshort-enums} is the default; this is
495 determined by the ABI@.
497 @end itemize
499 @node Qualifiers implementation
500 @section Qualifiers
502 @itemize @bullet
503 @item
504 @cite{What constitutes an access to an object that has volatile-qualified
505 type (C90 6.5.3, C99 6.7.3).}
507 Such an object is normally accessed by pointers and used for accessing
508 hardware.  In most expressions, it is intuitively obvious what is a read
509 and what is a write.  For example
511 @smallexample
512 volatile int *dst = @var{somevalue};
513 volatile int *src = @var{someothervalue};
514 *dst = *src;
515 @end smallexample
517 @noindent
518 will cause a read of the volatile object pointed to by @var{src} and store the
519 value into the volatile object pointed to by @var{dst}.  There is no
520 guarantee that these reads and writes are atomic, especially for objects
521 larger than @code{int}.
523 However, if the volatile storage is not being modified, and the value of
524 the volatile storage is not used, then the situation is less obvious.
525 For example
527 @smallexample
528 volatile int *src = @var{somevalue};
529 *src;
530 @end smallexample
532 According to the C standard, such an expression is an rvalue whose type
533 is the unqualified version of its original type, i.e. @code{int}.  Whether
534 GCC interprets this as a read of the volatile object being pointed to or
535 only as a request to evaluate the expression for its side-effects depends
536 on this type.
538 If it is a scalar type, or on most targets an aggregate type whose only
539 member object is of a scalar type, or a union type whose member objects
540 are of scalar types, the expression is interpreted by GCC as a read of
541 the volatile object; in the other cases, the expression is only evaluated
542 for its side-effects.
544 @end itemize
546 @node Declarators implementation
547 @section Declarators
549 @itemize @bullet
550 @item
551 @cite{The maximum number of declarators that may modify an arithmetic,
552 structure or union type (C90 6.5.4).}
554 GCC is only limited by available memory.
556 @end itemize
558 @node Statements implementation
559 @section Statements
561 @itemize @bullet
562 @item
563 @cite{The maximum number of @code{case} values in a @code{switch}
564 statement (C90 6.6.4.2).}
566 GCC is only limited by available memory.
568 @end itemize
570 @node Preprocessing directives implementation
571 @section Preprocessing directives
573 @xref{Implementation-defined behavior, , Implementation-defined
574 behavior, cpp, The C Preprocessor}, for details of these aspects of
575 implementation-defined behavior.
577 @itemize @bullet
578 @item
579 @cite{How sequences in both forms of header names are mapped to headers
580 or external source file names (C90 6.1.7, C99 6.4.7).}
582 @item
583 @cite{Whether the value of a character constant in a constant expression
584 that controls conditional inclusion matches the value of the same character
585 constant in the execution character set (C90 6.8.1, C99 6.10.1).}
587 @item
588 @cite{Whether the value of a single-character character constant in a
589 constant expression that controls conditional inclusion may have a
590 negative value (C90 6.8.1, C99 6.10.1).}
592 @item
593 @cite{The places that are searched for an included @samp{<>} delimited
594 header, and how the places are specified or the header is
595 identified (C90 6.8.2, C99 6.10.2).}
597 @item
598 @cite{How the named source file is searched for in an included @samp{""}
599 delimited header (C90 6.8.2, C99 6.10.2).}
601 @item
602 @cite{The method by which preprocessing tokens (possibly resulting from
603 macro expansion) in a @code{#include} directive are combined into a header
604 name (C90 6.8.2, C99 6.10.2).}
606 @item
607 @cite{The nesting limit for @code{#include} processing (C90 6.8.2, C99
608 6.10.2).}
610 @item
611 @cite{Whether the @samp{#} operator inserts a @samp{\} character before
612 the @samp{\} character that begins a universal character name in a
613 character constant or string literal (C99 6.10.3.2).}
615 @item
616 @cite{The behavior on each recognized non-@code{STDC #pragma}
617 directive (C90 6.8.6, C99 6.10.6).}
619 @xref{Pragmas, , Pragmas, cpp, The C Preprocessor}, for details of
620 pragmas accepted by GCC on all targets.  @xref{Pragmas, , Pragmas
621 Accepted by GCC}, for details of target-specific pragmas.
623 @item
624 @cite{The definitions for @code{__DATE__} and @code{__TIME__} when
625 respectively, the date and time of translation are not available (C90
626 6.8.8, C99 6.10.8).}
628 @end itemize
630 @node Library functions implementation
631 @section Library functions
633 The behavior of most of these points are dependent on the implementation
634 of the C library, and are not defined by GCC itself.
636 @itemize @bullet
637 @item
638 @cite{The null pointer constant to which the macro @code{NULL} expands
639 (C90 7.1.6, C99 7.17).}
641 In @code{<stddef.h>}, @code{NULL} expands to @code{((void *)0)}.  GCC
642 does not provide the other headers which define @code{NULL} and some
643 library implementations may use other definitions in those headers.
645 @end itemize
647 @node Architecture implementation
648 @section Architecture
650 @itemize @bullet
651 @item
652 @cite{The values or expressions assigned to the macros specified in the
653 headers @code{<float.h>}, @code{<limits.h>}, and @code{<stdint.h>}
654 (C90 and C99 5.2.4.2, C99 7.18.2, C99 7.18.3).}
656 Determined by ABI@.
658 @item
659 @cite{The number, order, and encoding of bytes in any object
660 (when not explicitly specified in this International Standard) (C99 6.2.6.1).}
662 Determined by ABI@.
664 @item
665 @cite{The value of the result of the @code{sizeof} operator (C90
666 6.3.3.4, C99 6.5.3.4).}
668 Determined by ABI@.
670 @end itemize
672 @node Locale-specific behavior implementation
673 @section Locale-specific behavior
675 The behavior of these points are dependent on the implementation
676 of the C library, and are not defined by GCC itself.