3 ms·
There is no restriction against TCO in the C standard either. TCO is a valid optimization for a compiler to apply. So what is incorrect about it?
by stonemetal 15y ago
There is no restriction against TCO in the C standard either. TCO is a valid optimization for a compiler to apply. So what is incorrect about it?
- dchest 15y agoBecause it relies on the particular implementation of C compiler, not on the C standard. Take -Os flag away or use a compiler that doesn't have TCO, and the program has a bug. See also: * using memcpy() for overlapping regions (relies on the particular implementation of memcpy(); was exposed by a change in glibc - http://lwn.net/Articles/414467/ http://lwn.net/Articles/414467/); * memory aliasing assumptions; * passing NULL, 0 to memcpy() (http://code.google.com/p/spiped/source/detail?r=8 http://code.google.com/p/spiped/source/detail?r=8); etc.
- stonemetal 15y agoIt is ansi C standard code. There is an implementation limitation (stack size) that this program runs into. However that doesn't violate the C standard in any way, because the standard doesn't specify available stack space. So the program is compatible with certain C implementations in certain configurations. Given the C standard allows a C implementation to pick any stack size they like (including zero) we could claim that about all valid C programs that make any use of the stack.