The Cellar

The Cellar (http://cellar.org/index.php)
-   Technology (http://cellar.org/forumdisplay.php?f=7)
-   -   C++ Help, Please. Thank You. (http://cellar.org/showthread.php?t=23991)

Flint 11-29-2010 12:52 PM

Quote:

This is because !(a) is actually calling a().
No. It isn't. It is crucial for you to realize that this is where you are wrong.

!(a) where (a) is a bool function evaluates true or false, it doesn't literally execute the function.



Really, it doesn't. It doesn't do that.



Really.

Happy Monkey 11-29-2010 01:56 PM

You are wrong. The 'true' or 'false' that a() evaluates to is the one that is returned in the body of the function as it executes. I don't know where you think that value comes from if it doesn't come from the execution of the function.

Try this:

Add a second parameter to a() and b(), and pass in a unique value to each call. At the beginning of a() and b(), print out that value.

Quote:

bool a(pw, x)
{
cout << "a " << pw << " " << x << endl;
...
}

bool b(pw, x)
{
cout << "b " << pw << " " << x << endl;
...
}

while !(a(pw,1)) or !(b(pw,2))
{
if !(a(pw,3))
call (a(pw,4))

if !(b(pw,5))
call (b(pw,6))
}
If you keep entering short, numberless passwords then you will see all six.

Flint 11-29-2010 02:57 PM

Everything that you've said was supposed to happen (posts #8, 13, 15, 19, 25) doesn't happen. I don't see how showing you another example that doesn't happen will be more convincing than the overwhelming evidence I've already presented.

Happy Monkey 11-29-2010 05:51 PM

It will happen.

I withdrew my predictions from 8 and 13 already.

I don't think you've tested whether the things I've said were supposed to happen in 15, 19, and 25 are happening. They wouldn't affect what you see in your normal execution, just what is happening behind the scenes. As I said, the while loop is correcting for the strange behavior of the functions, and it seems to me that all of the overwhelming evidence you have presented includes the while loop.

If you test the functions alone, not in a while loop, you can see the side effects:

main()
{
cin.getline(pw)
if (a(pw))
cout << "a returned true, pw is now " << pw << endl;
else
cout << "a returned false, pw is now " << pw << endl;
}

If you enter a bad password, it will ask for another. If you enter another one, it will return false, even if the second one was good.


All times are GMT -5. The time now is 02:36 AM.

Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.