4 ms·
Historically that is incorrect. Remember that the C standard came about many years after the language was already in use, the C abstract machine wasn't an expl
by nyrikki 2y ago
Historically that is incorrect.
Remember that the C standard came about many years after the language was already in use, the C abstract machine wasn't an explicitly design for portability and performance, it was documenting an existing system.
C compilers being performant and portable is partly due to luck but mostly due to hard work by very smart people.
Last time I looked, clangs analysis and optimizing code was more than a quarter of a million lines as an example.
C being imperative is probably a lens for understanding how the type of optimization you are talking about are opportunistic and not intrinsic.
Another lens is to consider that the PDP11 had flat memory, but NUMA, l2 and l3 caches and deep pipelines make the compiler far more complicated despite maintaining that simple model on the abstract machine.
Ironically, FORTRAN, which was written on IBM machines that had decrementing index registers.
While the base one indexing is explained as being simply a choice of lowest value. In the historic context is is better conceptualized as a limit index.
That more closely matches what you are describing above. If you look at the most recent CPP versions adding ranges, that is closer to both FORTRAN and the above IMHO.
https://en.cppreference.com/w/cpp/ranges https://en.cppreference.com/w/cpp/ranges
That history is complicated because Dennis Ritchie's work on college was on what he called 'loop programming', what we would call the structured paradigm today.
That does have the concept that any loop that you know the number of iterations will always halt, but being imperative, C doesn't really enforce that although any individual compiler may.
C compilers are u reasonably effective in optimization, but that is in spite of the limits of the C abstract machine, not because of it .
As shown above, all it takes is one powerful actor like MS making a decision, that probably was justified at the time, to introduce side effects across all platforms.
Often it is safe to assume that the compiler will make good decisions, other times you have to force it to make the correct decision.
But using the default types is a decision more of a choice to value portability than about performance IMHO.
- nyrikki 2y agoProbably should point out that for loops in C are syntactic sugar for while loops at the language level. for loop Executes a loop. Used as a shorter equivalent of while loop. https://en.cppreference.com/w/c/language/for https://en.cppreference.com/w/c/language/for I am amazed at how good compilers are today. There is also the difference between portability, where it means it compiles vs meaning that the precision and behavior is similar across platforms. long would be more portable for a successful compilation but may cause side effects. I shouldn't have switched meanings in the above reply context.
- deleted 2y ago[deleted]