News for hackers. Stuff that matters.
Re:How to C in 2016 by Nursie on Friday January 08, 2016 @12:23PM (#10866498)
>> [u]intN_t may not exist.

It will, that's guaranteed by the standard. If it's not a standards compliant compiler/runtime/platform, you've got bigger problems.

>> If you are working with arrays, always use size_t if not, use [u]int_leastN_t

Sure, on array indices, size_t is appropriate.

I can't see an advantage in using 'least' as standards dictate that 8/16/32/64 bit types are available.

>> in 99% of the cases, except if you are working with network protocols, [u]intN_t is a bad choice

No, it's the best choice in most cases because it makes the code a little more explicit and easier to understand, and it makes developers think about the range of the data you're using.

Re:How to C in 2016 by to3m on Friday January 08, 2016 @01:50PM (#10867196)
The sized types are optional, since they are more restrictive than the ordinary types - see section 7.20.1.1 in the standard (http://port70.net/~nsz/c/c11/n1570.html#7.20.1.1). To summarize: intN_t is exactly N bits, with zero padding bits, and 1 2's complement sign bit; uintN_t is exactly N bits, with zero padding bits; the implementation must provide such typedefs for all such types it supports.

So, if a system is 1's complement, you won't get the intN_t types at all. If the system doesn't support a particular bit width, you won't get the types for that width.

Re:How to C in 2016 by bsder on Friday January 08, 2016 @09:41PM (#10869837)
> So, if a system is 1's complement

As someone who actually programmed a 1's complement system with end-around carry, I'm going to call you out on this.

What system still exists that can run C99 and is one's complement?

Re:How to C in 2016 by to3m on Friday January 08, 2016 @10:11PM (#10869919)
I am playing the language lawyer game - there is nothing to call out. Is what I say justified by the standard? Yes, or no? There are no other issues involved ;)

I have no idea if C99 runs on any 1's complement systems. I don't know what end-around carry is. I don't care what it is. I don't care about any of this 1's complement nonsense. But the standard says it exists, and must be taken into account, and, therefore, by the rules of the game, I am obliged to assume these things.