Because in C, declaration and initialization are intentionally different steps . They are deliberately different from each other because that is how C. is designed.
If you say this inside a function:
void demo(void) { int *param; ... }
You say: "My dear C compiler, when you create a stack frame for this function, don't forget to reserve sizeof(int*) bytes for storing the pointer." The compiler does not ask what is happening there - it is assumed that you will tell it soon. If you do not, maybe the best language for you;)
It might not be devilishly difficult to create some secure stack cleanup code. But that would have to be called on every function call, and I doubt that many C developers will appreciate the hit when they are just about to fill it themselves anyway. By the way, you can do a lot for performance if you are allowed to be flexible with the stack. For example, the compiler can do optimizations where ...
If your function1 calls another function2 and stores its return value, or maybe there are some parameters passed to function2 that do not change inside function2 ... we donβt need to create extra space, right? Just use the same part of the stack for both! Please note that this directly contradicts the concept of stack initialization before each use.
But in a broader sense (and, which, in my opinion, more importantly), he aligned himself with the philosophy of C, so as not to do more than is absolutely necessary. And this applies to whether you work on PDP11, PIC32MX (for which I use it) or Cray XT3. This is exactly why people can use C instead of other languages.
- If I want to write a program without tracing
malloc and free , I do not need to! Memory management is not imposed on me. - If I want to beat a packet and collect data to combine data, I can! (Until, of course, I read my implementation notes on standard commitment.)
- If I know exactly what I am doing with the stack frame, the compiler should not do anything for me!
In short, when you ask the C compiler to jump, it does not ask how tall. The resulting code will probably not even return.
Since most people who prefer to develop in C seem like this, he has enough inertia to not change. Your path may not be inherently a bad idea, but simply not asked by many other C developers.
detly Jun 23 '10 at 13:50 2010-06-23 13:50
source share