double f( std::string x )
{
return 2.0;
}
void main ()
{
double d = f("");
std::cout << f("");
std::cout << d;
}
something weird...is this a compiler bug?
i had some problem with a function returning very unusual (read: impossible) values and tracked the error down...it''s actually reproducible and happens even in such a simple piece of code that it''s obvious it can''t be right...so i''m wondering what exactly is wrpng here or if its a compiler error (I''m using VC++ 5 prof.)
here is the code:
it''s obvious that this should do nothing more then write 2 two times to stdout.
but for some reason i cant figure out it doesnt do so in a release build.
the second time (when it should write d) it doesnt write 2, but some gibberish (its always 1,something e-301, not even a constant number each time i run it).
if i change the std::string x to anything else, e.g. char* x then the thing works, and it also works if i put the line
double d = f("");
after
std::cout << f("");
but i''ll be darned, thats just the same!
i just dont understand why it does that.
since its only in release mode i also cant debug it so i really have no idea why this is happening, and why it only happens with std::string as an unused function parameter
and, even weirder: when i change the f from return type double to int it works again...
am i just really dumb and missing something obvious here or what is up?
hope someone has an answer...i feel really dumb at not being able to figure this simple looking problem out
Runicsoft -- latest attraction: obfuscated Brainfuck Interpreter in SML
This post was made entirely from re-cycled electrons
quote:Original post by civguy
yes it's a compiler bug. Btw, main should be int main()
Ok then i can sleep in peace now
and i know that it should be int main, i just did this for simplicities sake
Runicsoft -- latest attraction: obfuscated Brainfuck Interpreter in SML
This post was made entirely from re-cycled electrons
[edited by - Burning_Ice on January 19, 2003 6:19:20 PM]
Hey, int main() is even shorter to type. One doesn''t have to explicitely return anything from it. So this is ok: int main() {}
quote:Original post by civguy
Hey, int main() is even shorter to type. One doesn''t have to explicitely return anything from it. So this is ok: int main() {}
yes but (at least thats the warning i get from VC++) the compiler automatically changes it to type void if you dont return anything, so either i would have to write the return or live with the compiler warning...so i prefer void main to make it short hehe
Runicsoft -- latest attraction: obfuscated Brainfuck Interpreter in SML
This post was made entirely from re-cycled electrons
I guess VC++ 5.0 must not be very standards compliant. main must have a return value of type int; if you do not explicitly return a value (which you don''t have to), the return value is assumed to be 0.
quote:Original post by Miserablewell that''s news
I guess VC++ 5.0 must not be very standards compliant.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement