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.
I'd like to see the gcc ".." operator for range-based switch cases and designated initializers become standardized.
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;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.
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.
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.
while (true) {
const bool flag = do_something();
if (!flag) break;
}Principle 13: Unlike for C99, the consensus at the London meeting was that there should be no invention, without exception. Only those features that have a history and are in common use by a commercial implementation should be considered
#define AUTO(var, def) __typeof__(def) var = (def)
AUTO(x, 3);static lifetime compound literals. I don't see any reason not to be able to get the same effect as string literals for other types like:
return (static int const []){1, 2, 3};
Disallowing branch-predicted values for relaxed atomic operations. I think c++ did this and it seems the sane way to go.
Binary literals and binary printf format specifier. It would just occasionally be nice compared to hex.
countof macro for arrays. I don't even care if it checked for non-array type errors, it would just be nice for it to be standard.
Statement expressions and function literals would be nice, but I don't feel strongly about it.
_Auto
and then add a header like <stdauto.h> which does #define auto _Auto
like they did with _Bool in C99?1.8: What's the auto keyword good for?
Declaring vehicles.
struct car { ... };
which would get cumbersome to type.But "auto int x = 3;" is valid (and the "auto" keyword is useless in that context).
do {
} while(!do_something());
Not trying to be snarky, I'd just like to understand :) do {
const bool flag = do_something();
do_something_else();
} while(!flag);
Or like this: do {
int whatever = get_some_data();
const bool flag = do_something(whatever);
} while(!flag); while (true) {
const bool flag = do_something();
if (!flag) break;
}
Is it not what grandparent wanted?Not language, rather standard library, but I would like to see a new allocation API with explicit control over alignment, separation of reserving and committing addresses, and generally updated for the fact that memory systems are different now than they were in 1979.
aligned_alloc is alright, except there's no aligned_realloc. Linux always reserves addresses and doesn't commit until it needs to, but that can't be relied on for portable code.
In short: we're in a 64-bit, virtual memory world. I don't want an allocator design from 1979.
It's about time glibc's custom streams[1] get standardized. Real talk, it's 2016 and we can't define custom FILE * types. This doesn't even need to expose the libc's FILE implementation; it can remain opaque just fine.
Language-wise, I'd like to see a pragma to covert an array of structs to a struct of arrays; i.e. declare
#pragma struct SOA
struct entity {
uint32_t id;
...
};
struct entity all_entities[1000];
and have the compiler rewrite it to struct {
uint32_t id[1000];
...[1000];
} all_entities; // where typeof(all_entites[N]) == typeof(struct entity)
à la Jai[2]. This isn't a particularly hard transformation to do by hand, but it's kind of tedious.Standardizing M4 as a preprocessor would be a nice-to-have; i.e. you should be able to compile a .h.m4 or .c.m4 file directly. I don't know why GCC can't do this yet. It's a bit of a niche thing, but some of us are M4 addicts.
C is in a pretty good place otherwise. I like to think there are 3 known local optima in terms of programming languages: C, Lisp, and Forth. All of them are a little hard at first, but quickly become very easy to think in.
We'll probably never get any of this, which is a little depressing. I get the feeling the C committee doesn't really care that much about evolving the language any more. Modern, fast, safe(-ish), readable code is a GCC extension.
1. http://www.gnu.org/software/libc/manual/html_node/Custom-Str... 2. https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md...
The big problem with extending the C language is that C's in a ton of places. Some of the things you describe would mean increasing the size of the C runtime, which would be unacceptable in embedded programming and the like. Perhaps we need a middle ground language here -- more daring than C, more conservative than C++ -- where ideas can be tuned better and/or be specified for system types. C's universal assembly role really is a double edged sword as far as getting new stuff in the language.
Adding Lisp-style AST macros to C is never gonna happen[1], though it would be cool. I'm of the opinion that text macros and ‘real’ macros complement each other anyway.
One of these days I'll get around to implementing a less-portable-more-cool-C. There's Jai[2], but I don't really agree with all of its design (understandable, since I'm not a game developer).
--
1. Just kidding, people have done it already; e.g. https://github.com/eudoxia0/cmacro but it'll probably never be part of the standard.
2. https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md
int x = something();
do {
const int x = somethingElse();
...
} while (x != 42);
I'm a pretty hardcore C programmer (been using it as my absolute main and favorite language for over 20 years), yet I find it hard to come up with some wishes for what I'd like to see.
Not sure how to interpret that, perhaps it's just indicative of a certain ... conservatism common in old people? :) Scary thought!
To be brutally concrete, I sometimes wish I could write someting like this:
That'd be very useful, but of course in current standards it's not possible since 'flag' isn't valid outside the scope it's declared in. So now we have to pre-declare 'flag' before the loop, breaking const-cleanliness too of course. This is obviously not a show-stopper, it's a minute thing. But it would be so nice! :)Some support for automatic type inference would be nice, since most right-hand-side expressions have a type anyway it would be cool to be able to write
and have the type of 'x' be 'int' since that is the type of the literal '3'. Of course re-using "auto" like this would break their guiding principle, but it would look great (and, I think, somewhat mimic what C++ has done to that keyword).Does anyone have some better ideas?