Talk:Bit field

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing (Rated Start-class)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 

Critisism[edit]

Is this text really correct? Isn't it too harsh?

However, bit members in structs have potential practical drawbacks. First, the ordering of bits in memory is cpu dependent and memory padding rules can vary between compilers. In addition, less well optimized compilers sometimes generate poor quality code for reading and writing bit members and there are potentially thread safety issues relating to bit fields because most machines cannot manipulate arbitrary sets of bits in memory, but must instead load and store whole words

abelson (talk) 12:54, 8 April 2010 (UTC)

Misc[edit]

I'm quite surprised about this statement:

unsigned int likesIceCream : 1;

I guess it means "create an unsigned int with the size of 1 bit", so would

unsigned int myVar : 4;

create a 4-bit unsigned int variable by the name myVar? Is this colon operator defined in the ANSI C standard? --Abdull 19:08, 26 January 2007 (UTC)

Isn't the first thing ("|= flag") a bitmask, and only the second thing ("unsigned int a:1") a bit field? exe 11:42, 10 June 2007 (UTC)
This entire article seems quite bizarre, given that the term "bitfield" has a standard meaning in C, which is quite different than the meaning used in the article, and the examples are all in C.... (and indeed, use C bitfields). I've honestly never come across the term used in the sense the article describes (whereas the standard C meaning is quite widespread, at least in circles where C is used).
[Oh, and Abdull: yes the ": 4" syntax is quite standard, and has been in C for a very, very long time; that's exactly what a C bitfield is.]
--Snogglethorpe (talk) 12:50, 6 August 2008 (UTC)
Thread safety issue is not specific to bitfields. Many compilers allow command-line, #pragma or built-in switches to align structure differently than architecture expects. E.g. the following structure will have the same thread safety issues (GCC-specific example):
struct foo
{
  unsigned char flag;
  unsigned short counter;
} __attribute__ ((packed));
Stargazer3p14 (talk) 08:27, 29 April 2010 (UTC)
Found it: the current ISO/IEC standard ( http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf ) defines bit-fields in 6.7.2.1.8 . --Abdull (talk) 08:39, 10 June 2010 (UTC)

Easier readability, recommended by whom?[edit]

From the original article, after the first C example code block (emphasis mine):

the use of the bit shift operator (1 << 3) with an incrementing shift operand is recommended for easier readability.

While I have no doubt that it is more readable, I must question whether such a practice is actually recommended, and by whom, since I believe most programmers that use bit fields would (and should) be familiar enough with hex numbers to use them instead (0x01, 0x02, 0x04, 0x08, 0x10 ...). I have changed the word "recommended" to "used", but if anyone can find a notable source for such a recommendation, please feel free to change the wording back. C xong (talk) 03:25, 19 July 2010 (UTC)

Confusing usage of "Bitfield"[edit]

This article ought to have a link in it (unfortunately I don't know how to do it correctly) to "Bitfield (C)" because this is very confusing. A C bitfield is different than this mess, and, as mentioned earlier, it is maximally unfortunate that this page uses examples in C that use the C bitfield (and some that don't). Perhaps the most useful edits would be to change all the examples to pseudo-code (and don't use C bitfields) and put a link up top to a separate disambiguated page "bitfield (C)". Perhaps I'll start working on this if it gets on my nerves enough soon. --Limited Atonement (talk) 15:13, 12 March 2011 (UTC)

Drawbacks of the structure-based approach[edit]

I recommend removing the example and commentary completely. The lack of thread-safety is not a "bitfield" problem, but related to the fact that two members of a structure are updated by two separate statements and the result is therefore non-atomic. This would be equally true of two integers, etc. Peter Flass (talk) 11:57, 22 June 2012 (UTC)

Error[edit]

The section stating "Obtaining the value of a particular bit can be simply down by left shifting (≪) 0, n amount of times" is incorrect. Shifting 0 will always yield 0. Could someone please correct this. 80.42.91.53 (talk) 01:11, 9 January 2014 (UTC)