1<html lang="en"> 2<head> 3<title>Structures unions enumerations and bit-fields implementation - Using the GNU Compiler Collection (GCC)</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Using the GNU Compiler Collection (GCC)"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="C-Implementation.html#C-Implementation" title="C Implementation"> 9<link rel="prev" href="Hints-implementation.html#Hints-implementation" title="Hints implementation"> 10<link rel="next" href="Qualifiers-implementation.html#Qualifiers-implementation" title="Qualifiers implementation"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 141998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 152010 Free Software Foundation, Inc. 16 17Permission is granted to copy, distribute and/or modify this document 18under the terms of the GNU Free Documentation License, Version 1.3 or 19any later version published by the Free Software Foundation; with the 20Invariant Sections being ``Funding Free Software'', the Front-Cover 21Texts being (a) (see below), and with the Back-Cover Texts being (b) 22(see below). A copy of the license is included in the section entitled 23``GNU Free Documentation License''. 24 25(a) The FSF's Front-Cover Text is: 26 27 A GNU Manual 28 29(b) The FSF's Back-Cover Text is: 30 31 You have freedom to copy and modify this GNU Manual, like GNU 32 software. Copies published by the Free Software Foundation raise 33 funds for GNU development.--> 34<meta http-equiv="Content-Style-Type" content="text/css"> 35<style type="text/css"><!-- 36 pre.display { font-family:inherit } 37 pre.format { font-family:inherit } 38 pre.smalldisplay { font-family:inherit; font-size:smaller } 39 pre.smallformat { font-family:inherit; font-size:smaller } 40 pre.smallexample { font-size:smaller } 41 pre.smalllisp { font-size:smaller } 42 span.sc { font-variant:small-caps } 43 span.roman { font-family:serif; font-weight:normal; } 44 span.sansserif { font-family:sans-serif; font-weight:normal; } 45--></style> 46<link rel="stylesheet" type="text/css" href="../cs.css"> 47</head> 48<body> 49<div class="node"> 50<a name="Structures-unions-enumerations-and-bit-fields-implementation"></a> 51<a name="Structures-unions-enumerations-and-bit_002dfields-implementation"></a> 52<p> 53Next: <a rel="next" accesskey="n" href="Qualifiers-implementation.html#Qualifiers-implementation">Qualifiers implementation</a>, 54Previous: <a rel="previous" accesskey="p" href="Hints-implementation.html#Hints-implementation">Hints implementation</a>, 55Up: <a rel="up" accesskey="u" href="C-Implementation.html#C-Implementation">C Implementation</a> 56<hr> 57</div> 58 59<h3 class="section">4.9 Structures, unions, enumerations, and bit-fields</h3> 60 61 <ul> 62<li><cite>A member of a union object is accessed using a member of a 63different type (C90 6.3.2.3).</cite> 64 65 <p>The relevant bytes of the representation of the object are treated as 66an object of the type used for the access. See <a href="Type_002dpunning.html#Type_002dpunning">Type-punning</a>. This 67may be a trap representation. 68 69 <li><cite>Whether a “plain” </cite><code>int</code><cite> bit-field is treated as a 70</cite><code>signed int</code><cite> bit-field or as an </cite><code>unsigned int</code><cite> bit-field 71(C90 6.5.2, C90 6.5.2.1, C99 6.7.2, C99 6.7.2.1).</cite> 72 73 <p><a name="index-funsigned_002dbitfields-2233"></a>By default it is treated as <code>signed int</code> but this may be changed 74by the <samp><span class="option">-funsigned-bitfields</span></samp> option. 75 76 <li><cite>Allowable bit-field types other than </cite><code>_Bool</code><cite>, </cite><code>signed int</code><cite>, 77and </cite><code>unsigned int</code><cite> (C99 6.7.2.1).</cite> 78 79 <p>No other types are permitted in strictly conforming mode. 80<!-- Would it be better to restrict the pedwarn for other types to C90 --> 81<!-- mode and document the other types for C99 mode? --> 82 83 <li><cite>Whether a bit-field can straddle a storage-unit boundary (C90 846.5.2.1, C99 6.7.2.1).</cite> 85 86 <p>Determined by ABI. 87 88 <li><cite>The order of allocation of bit-fields within a unit (C90 896.5.2.1, C99 6.7.2.1).</cite> 90 91 <p>Determined by ABI. 92 93 <li><cite>The alignment of non-bit-field members of structures (C90 946.5.2.1, C99 6.7.2.1).</cite> 95 96 <p>Determined by ABI. 97 98 <li><cite>The integer type compatible with each enumerated type (C90 996.5.2.2, C99 6.7.2.2).</cite> 100 101 <p><a name="index-fshort_002denums-2234"></a>Normally, the type is <code>unsigned int</code> if there are no negative 102values in the enumeration, otherwise <code>int</code>. If 103<samp><span class="option">-fshort-enums</span></samp> is specified, then if there are negative values 104it is the first of <code>signed char</code>, <code>short</code> and <code>int</code> 105that can represent all the values, otherwise it is the first of 106<code>unsigned char</code>, <code>unsigned short</code> and <code>unsigned int</code> 107that can represent all the values. 108<!-- On a few unusual targets with 64-bit int, this doesn't agree with --> 109<!-- the code and one of the types accessed via mode attributes (which --> 110<!-- are not currently considered extended integer types) may be used. --> 111<!-- If these types are made extended integer types, it would still be --> 112<!-- the case that -fshort-enums stops the implementation from --> 113<!-- conforming to C90 on those targets. --> 114 115 <p>On some targets, <samp><span class="option">-fshort-enums</span></samp> is the default; this is 116determined by the ABI. 117 118</ul> 119 120 </body></html> 121 122