c++ - What's the result of a & b? -


this awkward, bitwise , operator defined in c++ standard follows (emphasis mine).

the usual arithmetic conversions performed; the result bitwise , function of operands. operator applies integral or unscoped enumeration operands.

this looks kind of meaningless me. "bitwise , function" not defined anywhere in standard, far can see.

i , function well-understood , may not require explanation. meaning of word "bitwise" should rather clear: function applied corresponding bits of operands. however, constitute bits of operands not clear.

what gives?

this underspecified. issue of standard means when refers bit-wise operations subject of few defect reports.

for example defect report 1857: additional questions bits:

the specification of bitwise operations in 5.11 [expr.bit.and], 5.12 [expr.xor], , 5.13 [expr.or] uses undefined term “bitwise” in describing operations, without specifying whether value or object representation in view.

part of resolution of might define “bit” (which otherwise undefined in c++) value of given power of 2.

and response was:

cwg decided reformulate description of operations avoid references bits, splitting off larger questions of defining “bit” , issue 1943 further consideration.

and defect report 1943 says:

cwg decided @ 2014-06 (rapperswil) meeting address limited subset of questions raised issues 1857 , 1861. issue placeholder remaining questions, such defining “bit” in terms of value of 2n, specifying whether bit-field has sign bit, etc.

we can see defect report 1796: all-bits-zero null characters meaningful requirement?, issue of standard means when refers bits affected/affects other sections well:

according 2.3 [lex.charset] paragraph 3,

the basic execution character set , basic execution wide-character set shall each contain members of basic source character set, plus control characters representing alert, backspace, , carriage return, plus null character (respectively, null wide character), representation has 0 bits.

it not clear portable program can examine bits of representation; instead, appear limited examining bits of numbers corresponding value representation (3.9.1 [basic.fundamental] paragraph 1). might more appropriate require null character value compare equal 0 or '\0' rather specifying bit pattern of representation.

there similar issue definition of shift, bitwise and, , bitwise or operators: specifications constraints on bit pattern of representation or on values resulting interpretation of patterns numbers?

in case resolution change:

representation has 0 bits

to:

value 0.

note as mentioned in ecatmur's answer draft c++ standard defer c standard section 5.2.4.2.1 in section 3.9.1 [basic.fundamental] in paragraph 3 not refer section 6.5/4 c standard @ least tell results implementation defined. explain in comment below c++ standard can incorporate text normative references explicitly.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -