Re:Elevate your C programming skills by exploring the SQLite...
by kardos on Sunday July 09, 2017 @12:29PM
(#14730503)
> I'd probably reduce usage of some sizeofs just using the constant
Why? The sizeof is resolved into a constant at compile time, ie, no runtime cost. I see the 'sizeof(i16)' as conveying more information than a '2'.
Re:Elevate your C programming skills by exploring the SQLite...
by aleksei on Sunday July 09, 2017 @12:29PM
(#14730504)
i16 seems to be a typedef for short int, which may be actually be larger than 2 bytes depending on the compiler.
Re:Elevate your C programming skills by exploring the SQLite...
by minipci1321 on Sunday July 09, 2017 @01:45PM
(#14730817)
Even more so:
-- the fact that the code didn't use the int16_t from stddef.h but rather defined their own, could hint in the sense that a signed-int-over-exactly-16-bits might be unavailable in the ABI. People defining their own exact-width integral types (instead of pulling in stddef.h), rarely think about how that makes the code harder to interpret for a reader.
Now, if the type i16 might indeed be wider than 16 bits, sizeof becomes perfectly justified but '16' is not.
Re:Elevate your C programming skills by exploring the SQLite...
by ivanbakel on Sunday July 09, 2017 @01:47PM
(#14730824)
If it's specified as i16, it would be exactly two bytes in all situations - there would be no logic in including a size parameter that didn't actually mean anything, and sized ints are specifically meant to be platform-independent.
I'm not sure all the casts are necessary, however, and I'd probably reduce usage of some sizeofs just using the constant (sizeof(i16) should obviously be 2, if the name is any indication.)