News for hackers. Stuff that matters.

annathebannana

Re:How to C in 2016 on Friday January 08, 2016 @10:21AM (#10865446)
If you are sure that this is going to be the case, then use uint_least8_t.
Re:How to C in 2016 on Friday January 08, 2016 @10:19AM (#10865430)
Both problems are being avoided if you use [u]int_leastN_t

Or if you do not make assumptions of the sizes of int, something that only bad programmers do.

Re:How to C in 2016 on Friday January 08, 2016 @10:14AM (#10865379)
Terrible

The first rule of C is to ALWAYS use C

The second rule of C is to NEVER use [u]intN_t, use [u]int_leastN_t instead and (unsigned) char when you want to deal with bytes

The 3rd rule of C is to never use anything else when size_t should be used

The 4th rule of C is that everyone has his own style, so declaring variables on top is totally acceptable (and more clean IMO)

The 5th rule of C is "enjoy your stack overflow" when using VLAs instead of malloc (not to mention that VLAs are optional in C11)

>which also means it's capable of holding the largest memory offset in your program.

wrong

>C99 gives us the power of <stdbool.h> which defines true to 1 and false to 0

I do use it but it is useless

>readability-braces-around-statements — force all if/while/for statement bodies to be enclosed in braces

don't use a shitty editor

>You should always use calloc

good thing calloc has: checks for overflows when multiplying the typesize and the arraylen

bad thing: makes programmers think that it will make your pointers null

>you can wrap it with #define mycalloc(N) calloc(1, N).

but the two arguments is the only good thing calloc has

>growthOptional

I can't see any reason why the second one is considered better

Re:How to C in 2016 on Friday January 08, 2016 @10:04AM (#10865305)
Do you have any reason for supporting uint16_t instead of uint_least16_t?

Their point is against portability as they may not exist at all.

Re:How to C in 2016 on Friday January 08, 2016 @10:02AM (#10865283)
[u]intN_t may not exist. If you are working with arrays, always use size_t if not, use [u]int_leastN_t

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