odd thing
Do you mean "can't" compile? If so it's probably because rand is declared in <cstdlib> not <iostream>. Well at least for me it is, but my header versions are rather old.
Quote:Original post by xor
You're compiling with optimization flags, that remove redundant code.
maybe you wrong,I remove <iostream>,so It can still compile. I use vc2003.net
*sigh*
NOT EVERYTHING IS IN IOSTREAM!!!
There's a reason why your include directory has many header files in it. Each of them declares different things.
Normally I'm not one to recommend programming books, but since you are incapable of solving the most simple problems and continue spamming the boards(9 topics in 1 day) I suggest you go buy a beginning C++ book or go to your local library.
NOT EVERYTHING IS IN IOSTREAM!!!
There's a reason why your include directory has many header files in it. Each of them declares different things.
#include <iostream>#include <cstdlib>int main(){float d = rand()%RAND_MAX;return 0;}
Normally I'm not one to recommend programming books, but since you are incapable of solving the most simple problems and continue spamming the boards(9 topics in 1 day) I suggest you go buy a beginning C++ book or go to your local library.
Well that sounds strange. Mabye it's because you're using .net, most C++ compilers should bitch at you for not including cstdlib. Anyway if it works what is this thread about?
For the love of God!!!
You compiling an empty main!
The optimization flag activates a method of optimization that consists of removing redundant code, code that isn't going to be needed is removed. So that line " float d = rand()/RAND_MAX;" is going to be removed, you're compiling an empty main. So it doesn't matter what headers you include or exclude, the thing is allways going to compile, because an empty main needs nothing.
Now if you want to check this, just include a "printf("%f\n");" at the end of that code and it won't compile. Why? Because now the variable 'd' is actually used somewhere, it is not redundant, it will not be removed by the optimization.
Quote:maybe you wrong,I remove <iostream>,so It can still compile. I use vc2003.net
You compiling an empty main!
The optimization flag activates a method of optimization that consists of removing redundant code, code that isn't going to be needed is removed. So that line " float d = rand()/RAND_MAX;" is going to be removed, you're compiling an empty main. So it doesn't matter what headers you include or exclude, the thing is allways going to compile, because an empty main needs nothing.
Now if you want to check this, just include a "printf("%f\n");" at the end of that code and it won't compile. Why? Because now the variable 'd' is actually used somewhere, it is not redundant, it will not be removed by the optimization.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement