I'm attending a C++ programming course. The teacher gave us some exercises, in which we must find what's wrong with the code.
The problem is I'm completly stuck in one of them. I tried to create and compile the following code: #include<iostream>
The problem is the compiler gives no errors and the program runs without any errors either.
Could someone PLEASE help me?
Thx in advance.
Name:
Anonymous2008-02-13 11:27
my_sym does not return anything
Name:
Anonymous2008-02-13 11:27
...
Name:
Anonymous2008-02-13 11:28
DONT HELP HIM
Name:
Anonymous2008-02-13 11:30
Hi.
I'm attending a trolling course. The teacher gave us some exercises, in which we must find what's wrong with the troll.
The problem is I'm completly stuck in one of them. I tried to create and compile the following troll:
You must rewrite my_sum in the ENTERPRISE READY way, fully object oriented client-server 100% reliable architecture designed according to the latest standards.
Name:
Anonymous2008-02-13 11:35
>>2
How yeah, I really am stupid. :P I didn't realise it was so simple.
But how come this code compiles and runs without problems?
Name:
Anonymous2008-02-13 11:35
The solution is easy, it's in a book called Structure and Interpretation of Computer Programs, check it out
>>7
Because your CFLAGS don't have the necessary -Warnings required
Name:
Anonymous2008-02-13 11:39
This is all true, but... how the fuck does it knows what to return???
Name:
Anonymous2008-02-13 11:43
>>1
The variable c is defined locally in the function my_sum, so you can't use c in the function main which is what you're trying to do. The solution is to define c as a global variable, like this: #include<iostream>
This way, you can simply generate a DOM tree and parse it in a simple manner - namely, see which sum contains matching inputs per your function, and return the result.
1. It didn't explode, probably because of a fabrication error.
2. My hand was not torn off
So, does this prove that throwing the firecracker is not required?
Name:
Anonymous2008-02-13 12:21
No, that proves you're a faggot
Name:
Anonymous2008-02-13 12:25
Is this a g++ bug, or is it a c++ feature?
It looks to me that an error should have appeard.
Name:
Anonymous2008-02-13 12:35
It's a nonstandard thing called "default return", i.e. if you don't return anything the value that was in the register is used, and that register (eax on x86) just happened to contain the result of the last calculation. Don't count on it.
Name:
Anonymous2008-02-13 12:40
Welcome to the wonderful world of undefinedbehaviour.
Name:
Anonymous2008-02-13 12:45
>>20
You right!
I've replaced the code in the function by: int c;
int d=7;
c=a+b;
int e=1+d;
and now it gives me always 8.
This is both strange and dangerous behaviour.
I'll have to be more carefull. Thx for the tip.
Yeah, cause whatever's left in the %eax register is what your function returns. - That is, on an IA-32 architecture. Otherwise would be some kind of other variable, i.e. if it was Sparc, it would be l7 or something since those have liek double the amount that IA-32 has. So the compiler is def using that register for doing the math and the result is simply getting left behind.
Name:
Anonymous2008-02-14 2:25
>>30
Sorry, you are not allowed to read the O3 docs until you have achieved O2 Satori and paid your fees to the Church of Expert Programmers.
Name:
Anonymous2008-02-14 3:34
you did not return c.
Name:
Trollbot90002009-07-01 10:59
Namespace std int my sum int a 70 NEXT I had no idea about optimizations sigh.