Re:My personal C coding style as of late 2023
by hasmanean on Monday October 09, 2023 @07:02AM
(#37819072)
Default signed/unsigned is not a platform convention but a compiler one. You can change it with a compiler switch, in the makefile.
Re:My personal C coding style as of late 2023
by chmod775 on Monday October 09, 2023 @07:36AM
(#37819289)
Then you're better off using custom types - that way people will immediate know your type is non-default - as opposed to hiding your customization away in a makefile, pranking people who expect built-ins to behave a certain way.
Re:My personal C coding style as of late 2023
by munch117 on Monday October 09, 2023 @12:31PM
(#37822106)
The people who understand that it can be either, depending on a compiler switch, are exactly the people who use an explicit sign (typically via a typedef) to ensure their code always works.
The people who say that char is de facto signed and everyone should just deal with it, are the people who end up writing broken code.
Re:My personal C coding style as of late 2023
by WalterBright on Monday October 09, 2023 @02:30PM
(#37823570)
Um, it was dependent on how the CPU handled it back in those days. That problem went away, though.
Re:My personal C coding style as of late 2023
by ChrisRR on Tuesday October 10, 2023 @07:12AM
(#37830663)
"might" be able to change it. It's fine in GCC based compilers, but some awkward/old compilers don't give you the luxury
Re:My personal C coding style as of late 2023
by WalterBright on Monday October 09, 2023 @02:30PM
(#37823565)
Yes, the optional sign on char is also madness. C had a chance in 1989 to make it unsigned, and muffed it. (When C86 decided between value-preserving and sign-preserving semantics, they could have also said char was unsigned, and saved generations of programmers from grief.)
D's `char` type is unsigned. Done. No more problems.
I therefore use typedefs called `byte` and `ubyte` wherever the data is 8-bit but not character data. I also use the aliases `ushort`, `uint` and `ulong` to cut down on typing. On the other hand, the types in <stdint.h> are often recognised by syntax colouring in editors where user-defined types aren't.