3 ms·
> Does anyone have some better ideas? gcc's C extensions have some good ideas [1], particularly: 1. typeof(e) operator: great for use in macros 2. labels as
by naasking 11y ago
> Does anyone have some better ideas?
gcc's C extensions have some good ideas [1], particularly:
1. typeof(e) operator: great for use in macros
2. labels as values: used in just about every language interpeter
3. statement expressions: great for use in macros
4. fixed point types: who wants to hack their own fixed precision arithmetic?
5. vector extensions
6. arithmetic functions with overflow checking
I think all of the above would make good additions to the C standard.
[1] https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
- kayamon 11y agoWell said. I'd like to see the gcc ".." operator for range-based switch cases and designated initializers become standardized.
- PeCaN 11y agoAs long as we keep __builtin_apply out of the standard, GCC is loaded with good ideas.
- naasking 11y agoYeah, after reading that I was really wondering about the use case for those extensions at the time they were added. I honestly can't think of any now.
- tropo 11y agoI'm not liking the fixed-point types. I'd rather see the ability to place an attribute on a floating-point variable that would inform the compiler that fixed-point might be suitable. You'd specify the requirements that need to be met, and the compiler would choose the fastest format for the current architecture. That format could be fixed-point, decimal float, IEEE float, or something weirder. For example, your requirements could include: minimum magnitude, maximum magnitude, minimum value, maximum value, maximum additive error, maximum multiplicative error, signed zero needed or not, NaN signed/unsupported/unsigned, infinity distinct from NaN and/or the largest number, etc. You say what you need for correctness, and the compiler makes it happen.
- _kst_ 11y agoFixed-point and floating-point types have very different behavior. I can't think of a case where I'd want to let the compiler decide which one to use.
- tropo 11y agoNo, normally what people desire of a fixed-point representation is a subset of a floating-point representation. Most fixed-point stuff is prototyped as floating-point, then painfully converted into a mess of nasty macros. Ideally there would be assertions to protect against failure due to the limited functionality of the fixed-point type, but probably you don't bother. It's not maintainable. We should be able to take that prototype, mark it up with hints for the compiler, and then build with fixed-point enabled.
- kps 11y agoTR 18037¹ defines fixed point arithmetic, but it does not seem well supported. ¹ http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1169.pdf http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1169.pdf
- _kst_ 11y agoAs far as I can tell, a programmer can't specify the number of fractional bits. The type "unsigned short _Fract", for example, has a number of fraction bits determined by the implementation within limits imposed by the standard. There's no way to ask for a type with, for example, 12 integral bits and 4 fractional bits. Do hardware constraints make, for example, an 8.8 bit format easier to handle than a 12.4 format? Compare Ada's fixed-point types, which let you specify the range and delta: type Fixed is delta 0.0625 range 0.0 .. 4095.9375;
- brandmeyer 11y ago> Do hardware constraints make, for example, an 8.8 bit format easier to handle than a 12.4 format? Sometimes they do. For example, the ARMv7 DSP extensions support signed Q0.31 and signed Q0.15 arithmetic much faster than any other fixed-point format.