JohnnyTheDon wrote:ru2aqare wrote:JohnnyTheDon wrote:#define is also nice when you need to define a lot of numerical constants.
That can be done using the const modifiers. Any sane compiler will recognize it's a constant value, and will not generate a memory access for the variable, it will simply inline the value.
But I agree doing it with preprocessor macros looks nicer.
GCC isn't sane then. It exports the const variables, causing a bunch of multiple definitions.
That they are exported doesn't mean they are not inlined in the current module. Also, to avoid that you can always declare them as static const (possibly in the header).
There's also a way I'm sure GCC inlines your constant. Inter-module analysis is achieved in GCC by feeding everything into it at once, and running with -O3 -fwhole-program -combine. Once, I did it on a university work and the boy inlined everything into a HUGE main(). I doubt this mass-inlining approach is always an intelligent optimization, however.
Also, when declaring global or stack arrays const variables cannot be used.
Did not remember that. In fact, in C this doesn't work.
However, in a modern language, you don't have to fear this limitation. In Java, you can put non-constant initializers in attributes (including static ones, afaik), and I guess you can do this in D and in C# either.
Alas, IMHO C has a very important role as a relatively low-level language, specially in operating system development (as all of you know). I think it would be a fairly good idea to redesign the language, not to bloat it and to add every imaginable feature, but just to modernize it. Removing that old header-inclusion scheme and that type-unsafe preprocessor, and instead rely on the compiler to optimize away unneeded code and function calls would help a lot. Adding namespaces and a template facility would also be a good idea.
Redesigning setjump/longjump in order to make it easer to implement threading libraries and SEH libraries without assembly code would be a good idea, too.
Personally, I don't like very much the C syntax. But killing would be a nasty idea. People love it.
I don't think it would be easy, though. There are also a bunch on C dialects out there, and non of them has the goal of cleaning-up the original language, so I don't think there are many people inclined to this kind of redesign to the language.
JJ