News for hackers. Stuff that matters.
Re:My personal C coding style as of late 2023 by ryandrake on Monday October 09, 2023 @11:44AM (#37821614)
Also: Embedded is almost the only time you really, truly need to care about how many bits a type is, and only when you're interacting with actual hardware.

For almost every other routine task in programming, I would argue that it really doesn't matter if your int is 32 bits wide or 64 bits wide. Why go through the trouble of insisting on int32_t or int64_t? It probably doesn't matter for the things you are counting.

Some programmers will say "Well, we should use int64_t here because int32_t might overflow!" OK, so why weren't you checking for overflow if it was an expected case? int64_t might overflow too, are you checking after every operation? Probably not. "OK, let's use uint64_t then, now we get 2x as many numbers!" Now you have other overflow (and subtraction) problems to handle.

Nowadays, I just use int and move on with my life. It's one of those lessons from experience: "When I was younger, I used int and char because I didn't know any better. When I was older, I created this complex, elaborate type system because I knew better. Now that I'm wise, I just use int and char."

Re:My personal C coding style as of late 2023 by terracottalite on Monday October 09, 2023 @12:17PM (#37821940)
> 2x as many numbers

Minor correction, 2^32x as many numbers. Though I agree with your point.

Edit: added x to the number for consistency and clarity.

Re:My personal C coding style as of late 2023 by ryandrake on Monday October 09, 2023 @12:31PM (#37822115)
LOL yea, that's what was in my brain but somehow 2x got typed. Good catch.
Re:My personal C coding style as of late 2023 by WalterBright on Monday October 09, 2023 @02:36PM (#37823637)
> It's one of those lessons from experience: "When I was younger, I used int and char because I didn't know any better. When I was older, I created this complex, elaborate type system because I knew better. Now that I'm wise, I just use int and char."

Right on, dude. I've gone full circle on that, too.

I also spent years wandering the desert being enamored with the power of the C preprocessor. Eventually, I just ripped it out as much as possible, replacing it with ordinary C code. C is actually a decent language if you eschew the damned preprocessor.

Re:My personal C coding style as of late 2023 by obviouslynotme on Monday October 09, 2023 @11:32PM (#37828235)
Sizing values is also great for reducing bandwidth footprint, either network or memory. The really good optimizations come from this.