News for hackers. Stuff that matters.
Re:My personal C coding style as of late 2023 by Nursie on Monday October 09, 2023 @04:10AM (#37818162)
> These types should be defined in the right header

stdint.h

It's always been amazing to me how many different projects I've worked on (not that I've been in professional C for about 7 years now)) that include their own painstaking recreation of this file.

Reusing them and effectively translating them just to your own name is just annoying to the reader IMHO. I am reminded of a C++ project I worked on, where I questioned the extensive use of typedefs around collections of things, various forms of references and compound objects etc. I was informed by one of the more experienced C++ folks that it made the code easier to comprehend.

Later I saw the typedef cheat-sheet sellotaped to the side of his monitor...

Re:My personal C coding style as of late 2023 by gallier2 on Monday October 09, 2023 @05:01AM (#37818440)
For bool it's even worse.
Re:My personal C coding style as of late 2023 by cesarb on Monday October 09, 2023 @07:33AM (#37819270)
> It's always been amazing to me how many different projects I've worked on (not that I've been in professional C for about 7 years now)) that include their own painstaking recreation of this file.

How many of them started before stdint.h existed? AFAIK, it's a somewhat recent addition to the C language, and IIRC, for a long time even after it became part of the C standard, some popular C compilers still didn't have it.

Re:My personal C coding style as of late 2023 by Nursie on Monday October 09, 2023 @08:49AM (#37819913)
As recently as eight years ago, on projects started within the previous handful of years. It’s more to do with a lot of C programmers being stuck in a sort of stasis IMHO. (I’m sure I was too in many ways).

And yes, Microsoft were the outlier and absolutely dragged their heels on stdint, but you could always grab a compliant implementation from one of the FOSS projects that produced one.

Re:My personal C coding style as of late 2023 by uxp8u61q on Monday October 09, 2023 @08:54AM (#37819965)
inttypes.h was added to C99. A quarter of a century ago.
Re:My personal C coding style as of late 2023 by yakubin on Monday October 09, 2023 @09:31AM (#37820291)
Many C codebases predate that. And Visual Studio for a long time didn’t support anything newer than C89.
Re:My personal C coding style as of late 2023 by eqvinox on Monday October 09, 2023 @11:32AM (#37821479)
There's no requirement for a born-1995 codebase to still build on a 1995 system in 2023.

I work on a born-1995 codebase. We started requiring an ISO C11 plus GNU extensions¹ several years ago and are actively removing "compatibility" checks and kludges that are outdated.

[¹ to be fair - not needing to support Windows is a godsend for any C project.]