News for hackers. Stuff that matters.
Re:Learn C The Hard Way by eliben on Saturday July 02, 2011 @10:49PM (#2722921)
My experience as an interviewer showed that in addition to the things you listed, people often fail to grasp binary representation of numbers in a computer at all.

This most often comes up when people are asked to do some binary manipulation of numbers, i.e.:

  unsigned u = 19;
  unsigned v = u >> 1;
"v" is now 9, and to really understand it one must grasp how numbers are represented in binary under the hood.

People also fail to understand strings:

  char* s = "string literal";
To some, it's absolutely opaque that the first byte "s" points to contains 0x73, and that represents "s" in ASCII.
Re:Learn C The Hard Way by tzs on Sunday July 03, 2011 @01:36AM (#2723165)
Does C require that you are running on a binary computer?

The C99 standard defines the >> operator in terms of division by powers of 2, so one can determine the result of 19 >> 1 without needing to know anything about how 19 is actually represented by the machine.

Re:Learn C The Hard Way by irahul on Saturday July 02, 2011 @11:50PM (#2723025)
> "v" is now 9, and to really understand it one must grasp how numbers are represented in binary under the hood.

Correct me if I am wrong, but I don't think C guarantees anything about the binary representation. Depending on the architecture, `v` can have different value.

Re:Learn C The Hard Way by spc476 on Sunday July 03, 2011 @01:10AM (#2723124)
C allows differences in how negative integers are represented (at least, C89 did---I'm not sure about C99 as I don't have the standard in front of me). There are three different ways to represent negative numbers in binary, sign magnitude, one's complement, and two's complement (these days, most computers are two's complement). The upshot is that you might end up with two type of zeros (sign magnitude, one's complement) or an unequal range of negative numbers (two's complement has one additional negative number) and taking the absolute value of an integer may not be possible for some values (given a 16-bit integer on a two's complement system, you cannot get the absolute value for -32,768, which is a valid integer on such a system).
Re:Learn C The Hard Way by bad_wolf on Sunday July 03, 2011 @12:06AM (#2723046)
If 19 is represented differently in binary on your platform than (leading zeros)10011, you are already quite screwed.

You might be thinking of character representation for the later example.

Re:Learn C The Hard Way by irahul on Sunday July 03, 2011 @01:18AM (#2723135)
No, I was thinking binary 19. Does C say the implementation is going to be 1s complements, 2s complements or whatever?

Is there anything that says, for example, it can't be BCD?

Re:Learn C The Hard Way by justincormack on Sunday July 03, 2011 @05:33AM (#2723413)
Yes even though this is exactly why people want to use C now, to get exact binary behaviour.