C bitmezo kerdes
Andras Tantos
andras at tantosonline.com
Wed Nov 7 17:11:30 CET 2007
Hali!
Nos, a szabvany nem sokat mond a bit-field-ek allokaciojarol. A legtobb
fordito szepen sorban elkezdi lerakni oket a memoriaban, azaz az alabbi
peldaban 'g' es 'f' kulon int-be kerul - valahol mintha meg olvastam is
volna ezt a szabvanyban, de most nem talalom sehol se. A szabvany maga ugy
tunik azonban mindezt nem specifikalja:
A member-declarator of the form
identifieropt : constant-expression
specifies a bit-field; its length is set off from the bit-field name by a
colon. The bit-field attribute is not part
of the type of the class member. The constant-expression shall be an
integral constant-expression with a
value greater than or equal to zero. The constant-expression may be larger
than the number of bits in the
object representation (3.9) of the bit-field's type; in such cases the extra
bits are used as padding bits and do
not participate in the value representation (3.9) of the bit-field.
Allocation of bit-fields within a class object
is implementation-defined. Alignment of bit-fields is
implementation-defined. Bit-fields are packed into
some addressable allocation unit. [Note: bit-fields straddle allocation
units on some machines and not on
others. Bit-fields are assigned right-to-left on some machines,
left-to-right on others. ]
A declaration for a bit-field that omits the identifier declares an unnamed
bit-field. Unnamed bit-fields are
not members and cannot be initialized. [Note: an unnamed bit-field is useful
for padding to conform to
externally-imposed layouts. ] As a special case, an unnamed bit-field with a
width of zero specifies alignment
of the next bit-field at an allocation unit boundary. Only when declaring an
unnamed bit-field may
the constant-expression be a value equal to zero.
Erdekes: egyreszt azt mondja, hogy az allokacio implementacio-fuggo, rogton
utana viszont definial egy modszert, amivel allokacios hatarra lehet
kenyszeriteni a forditot. Hat ez van, semmi se lehet tokeletes...
Ja, ez a C++ szabvany, a C lehet, hogy kicsit mast mond.
Udv,
Tantos Andras
----- Original Message -----
From: "Fuzesi Arnold" <arnold.fuzesi.lista at gmail.com>
To: <elektro at tesla.hu>
Sent: Tuesday, November 06, 2007 4:04 PM
Subject: C bitmezo kerdes
Sziasztok!
uint a:1
uint b:2
uint c:5
uint d:1
uchar helo
uchar belo
uint f:1
uint g:1
bitmezo eseten az "a,b,c,d" valtozokat egy uint-be teszi, majd két uchar
valtozo majd ujabb uint-be az "f,g", vagy az előző uint-ben ha van szabad
hely, akkor oda teszi az "f,g"-t?
Szabvany mit mond erre?
A.
-----------------------------------------
elektro[-flame|-etc]
More information about the Elektro
mailing list