posted 20 years ago
Yup - you're right. The compiler wasn't built by NASA engineers trying to send someone to Mars. It isn't going to check your logic to see if you're doing something you shouldn't be doing. In some cases, like your first example, the compiler will look for some simple error and tell you about them. However, what will the compiler check and what won't it check? The line had to be drawn somewhere. In many cases, the compiler simply checks syntax and puts the burden on you, the programmer, to ensure that your logic isn't causing a stack overflow or any other problem. This leads to a nice, lightweight compiler.
Could the developers of the compiler checked for such a thing as this? Probably. It also probably would have taken a lot of work for something that any competent developer should be able to avoid, anyway.
I hope that helps,
Corey