News for hackers. Stuff that matters.
Re:An update on GNU performance by seba_dos1 on Sunday October 21, 2018 @04:31PM (#18270048)
Signedness of "char" is purely platform-specific. If you want to write portable code, you always have to specify "signed" or "unsigned" before "char".
Re:An update on GNU performance by wereHamster on Sunday October 21, 2018 @04:41PM (#18270103)
Why not use {,u}int{8,16,32,64}_t from stdint.h? Then you don't have to think twice whether some type is signed or unsigned.
Re:An update on GNU performance by greglindahl on Sunday October 21, 2018 @06:09PM (#18270634)
stdint.h was introduced in C99, yes? There's a lot of code that started before that and hasn't been converted to newfangled things.
Re:An update on GNU performance by kllrnohj on Sunday October 21, 2018 @10:11PM (#18271655)
> newfangled things

stdint.h is nearing 20 years old now, I don't think it counts as a "newfangled thing" anymore.

But yes, there is plenty of very obsolete software still out there.

Re:An update on GNU performance by beefhash on Sunday October 21, 2018 @11:18PM (#18271954)
> stdint.h is nearing 20 years old now, I don't think it counts as a "newfangled thing" anymore.

In the world of C, it is. Custom compilers for particular embedded systems, such as MCUs, often only speak C89 and nothing else. C99 still hasn't found complete and widespread acceptance.

Re:An update on GNU performance by kllrnohj on Monday October 22, 2018 @10:45AM (#18275042)
The compiler is irrelevant here as stdint.h can come from a variety of sources. There's no reason to not have stdint.h, even on ancient as dirt embedded systems stuck on C89. Even in the worst case of there's no vendor-provided one you can still just define it yourself using a copy from almost anywhere else, there's very little to it.
Re:An update on GNU performance by beefhash on Monday October 22, 2018 @11:57AM (#18275736)
stdint.h can't be reliably be premade. A compiler is completely free to, say, define sizeof(unsigned int) to anything as long as it can represent at least 65535. stdint.h has to work with the C base types, so it does have to be customized for a particular compiler.
Re:An update on GNU performance by jcelerier on Monday October 22, 2018 @03:52AM (#18272897)
that's assuming your compiler even ships any kind of library outside of a header for your hardware's specific functions
Re:An update on GNU performance by AnaniasAnanas on Sunday October 21, 2018 @05:31PM (#18270410)
Because these are optional. Consider {,u}int_least{8,16,32,64}_t instead.
Re:An update on GNU performance by loeg on Sunday October 21, 2018 @06:39PM (#18270765)
Technically optional, yes. Any implementation that lacks them is in for a very bad time, though.
Re:An update on GNU performance by amelius on Sunday October 21, 2018 @05:34PM (#18270431)
> Why not use (...)

Because sometimes you are not the author of the software you want to port. Of course, when you start porting the software, you'd use a (predefined) typedef.

Re:An update on GNU performance by bpye on Sunday October 21, 2018 @05:16PM (#18270308)
The only argument I can see for using other types is for int, when you want the natural length integer, in any other case it seems to be than stdint.h types are better?
Re:An update on GNU performance by kazinator on Sunday October 21, 2018 @11:28PM (#18271991)
Using the natural integer whenever possible keeps the C code abstract. The program becomes less limited as it is ported to more capable machines with bigger integers, instead of continuing to pretend that everything is a 32 bit i386.

You need some low-level justification for using an uint32_t and such: like conforming to some externally imposed data format or memory-mapped register bank.

The justification for <stdint.h> is that it's better to have one way of defining these types in the language, than every program and every library in every program rolling its own configuration system for detecting types and the typedefs which name them. Let's see, for calling Glib, we use guint32, for OpenMax we use OMX_U32, ...

Funny how these situations persist almost 20 years after stdint.h was standardized (and a number of more years after being draft features).

Re:An update on GNU performance by bloomer on Sunday October 21, 2018 @11:57PM (#18272076)
Well, except that I don’t think most software authors actually know where it is possible to safely use an int versus one of the fixed width stdint types. In particular, you now need to make sure that your code works correctly no matter what the actual size of an int is. This involves complicated knowledge like int promotion rules and how they will interact with different sized int, long int etc. So instead of having portable software you just have software that may fail in unexpected ways on different types of machines. I don’t actually know the rationales , but I would think that making it easier to write portable software was possibly one of the goals of introducing stdint.
Re:An update on GNU performance by kazinator on Monday October 22, 2018 @03:05PM (#18277337)
The promotion rules only get worse when you use a type alias like int32_t, which could be a typedef for short, int, long or conceivably even char.

An expression of type int doesn't undergo any default promotion to anything, period; the widening promotion is only applied to the char and short types.

An int operand may convert to the type of an opposite operand in an expression, and an int argument or return value will convert to the parameter or return value type. That applies to int32_t also.

Anyway, you really have to know the rules to be working in C. Someone who uses fixed width types for everything doesn't know what they are doing and are just taking swipes at imaginary ghosts in the dark out of fear.

Re:An update on GNU performance by CamperBob2 on Monday October 22, 2018 @12:16AM (#18272137)
The program becomes less limited as it is ported to more capable machines with bigger integers, instead of continuing to pretend that everything is a 32 bit i386.

I'm guessing you've never ported code that was written for 32-bit ints back to a 16-bit architecture.

Always better to make your type sizes crystal-clear to the reader, IMO, even if it risks using a suboptimal word size on some other platform down the line.

Re:An update on GNU performance by lmm on Monday October 22, 2018 @05:13AM (#18273215)
> You need some low-level justification for using an uint32_t and such: like conforming to some externally imposed data format or memory-mapped register bank.

This is backwards. You should use uint32_t etc. like any higher-level language would, unless you have specific reasons to know you need a machine-sized type. Making your code behave differently in some arbitrary, untested way on machines with different default int sizes isn't going to make it "less limited", it's just going to make it broken.

Re:An update on GNU performance by kazinator on Monday October 22, 2018 @02:29PM (#18277030)
Can you cite one page in the K&R2 where the authors are using some 32-bit-specific integer? Or any other decent C book: Harbison and Steele? C Traps and Pitfalls?
Re:An update on GNU performance by seba_dos1 on Sunday October 21, 2018 @05:20PM (#18270327)
If you don't care about signedness of char, using it might be better for performance. Otherwise, yes, you're right.