Language:
switch to room list switch to menu My folders
Go to page: First ... 78 79 80 81 [82] 83 84 85 86 ... Last
[#] Sun Aug 14 2011 12:12:37 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


That's the answer I expected. "Maybe".

I had an amusing bug where I created a class whose creation logged that such-and-so started, and whose destructor logged that such-and-so ended, and I accidentally used this class like this:

ScopedLog( logLevel, "NameOfFunction" );

I was supposed to use it like this:

ScopedLog myLog( logLevel, "NameOfFunction" );

The previous way created a temporary object that disappeared immediately, so it always looked like nothing happened within the function ('cause the logging suggested that the function had finished when it hadn't even started).

I realize this case is rather different from yours, but it seems related, thanks to the whole temporary object thing.

[#] Mon Aug 15 2011 09:32:13 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

error condition? Sure, you could use pass-by-reference to return
either your value or the error conditions, but that can get messy. In

this scenario, exceptions can provide a somewhat more sensible
solution.

Nope. Return value is always success or failure, and return values are passed by value. Nowadays I have an object I call Ret. null on success, instance of Ret if failure with lots of failure details inside it. Return data is passed by reference in a parameter to the function.
There is no way you can tell me that random jumps of program flow is sensible in any context.

[#] Mon Aug 15 2011 09:32:57 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

But it's very damning to interrupt the flow of a program with an
exception for something as frivolous as, say, a missing file in the

yup. or converting a string to an integer and it's not an integer.

[#] Mon Aug 15 2011 09:34:19 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

/* stack variable */ foo = Bar(x, y, z) // constructor invocation
immediately followed by:
foo = Bar(z, y, x)

You're asking us? I thought you knew this stuff better than me. Or are you getting old and rusty too? :-)

No the destructor of the first object would not be called because it's being orphaned, but it still exists.

Or were you just testing us?

[#] Mon Aug 15 2011 09:37:50 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Ah ha! You were testing me, I am old, and I got it wrong. I totally misread your example. I saw an implicit 'new' in there where you didn't actually have one.
So lets see, as fleeb says it a temporary object is made, but it is still orphaned because the temporary object gets lost.

[#] Mon Aug 15 2011 09:39:28 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I am old. I'm going to fail my next interview. I'm going to have to write java for the rest of my life. Sigh.

[#] Mon Aug 15 2011 10:58:48 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


You're just used to using the heap. All the cool kids use the stack now.

[#] Mon Aug 15 2011 11:11:51 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

There is no way you can tell me that random jumps of program flow is

sensible in any context.

Random jumps of program flow are sensible in ANY context! >:)

[#] Mon Aug 15 2011 11:15:39 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


The drummer for your rimshot was carried away by an exception.

[#] Mon Aug 15 2011 11:19:26 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


the variable named foo is constructed once and copied once, and finally destructed when the frame goes out of scope. The temporary object is constructed, copied to foo, and immediately destructed. The previous value assigned to foo is *not* destructed before being reassigned, so if there is some dynamic allocation hidden inside the class, there needs to be an operator== that handles the reassignment sanely.

I don't know what the heck you would do if there was a derived class, so it seems that reass'ing a variable by value in C++ is something that should be avoided in the general case.


It was an honest question because I haven't used C++ in years and somebody was asking me something related, for which I didn't have a concise answer off the top of my head.

[#] Mon Aug 15 2011 15:06:36 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


Or just use pointers. Heh.

[#] Tue Aug 16 2011 10:41:20 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

it already exists, it's called while(1)

[#] Mon Aug 15 2011 13:50:16 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

reassigned, so if there is some dynamic allocation hidden inside the
class, there needs to be an operator== that handles the reassignment
sanely.

ahhh, it's alll coming back now... you're right, the way you make that work is by handling the operator= overload (that's what you meant right? not operator==) correctly.
So you CAN make it work right, but you have to handle all the assignment cases.

[#] Mon Aug 15 2011 13:48:06 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Random jumps of program flow are sensible in ANY context! >:)

NO! You can't say that!

[#] Mon Aug 15 2011 22:06:34 EDT from IGnatius T Foobar @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Random jumps of program flow are sensible in ANY context! >:)

We shall witness the triumphant return of the GOTO statement!!!!!1

[#] Tue Aug 16 2011 09:55:23 EDT from saltine @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I love GOTO

[#] Mon Aug 15 2011 13:48:18 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

The drummer for your rimshot was carried away by an exception.

SEEE!??!?!?

[#] Tue Aug 16 2011 16:10:00 EDT from skpacman @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

10 HOME
20 SWEET
30 GOTO 10



[#] Tue Aug 16 2011 20:23:41 EDT from zooer @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

 

Tue Aug 16 2011 16:10:00 EDT from skpacman @ Uncensored

10 HOME
20 SWEET
30 GOTO 10



]RUN

]SYNTAX ERROR IN 10



[#] Tue Aug 16 2011 23:03:01 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


10 ? HOME
20 ? SWEET
30 GOTO 10

That should work better.

Go to page: First ... 78 79 80 81 [82] 83 84 85 86 ... Last