Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Returning an array in C++

Name: Anonymous 2009-10-26 20:39

PLEASE /prog/ help me out here. I've read and tested at least 5 "answers" to my question that I've found on google, but I can't get any of them to work. You guys are better than them though, right?

I wanted to call an array by reference in a function. Then, I learned that that was impossible. I tried returning the array, but you can't do that either.

Apparently, I need to do some shit with pointers to return the array. How the fuck do I do this?

Name: Anonymous 2009-10-28 7:57

>>80
Yes you can. NOW YOUR'E THINKING WITH RUBY

Name: Anonymous 2009-10-28 8:07

>>71
but guess what, you don't need them in C because there's no such thing as exceptions

Right. You have returns instead. I mean, goto cleanup;.

You never programmed anything remotely complex in C, I guarantee that.

Name: Anonymous 2009-10-28 8:13

>>82
what was your point?

Name: Anonymous 2009-10-28 9:15

>>82

in C there's no way to protect against unwinding the stack, moron

Name: Anonymous 2009-10-28 9:19

>>82
nope. the closest thing to exception handling C has is signals.
it's the manly way of doing things.

Name: Anonymous 2009-10-28 9:28

>>85
setjmp & longjmp

Name: Anonymous 2009-10-28 10:39

>>86
TEN POINTS FOR GRYFFFFIINNNNDORRRRRRRR

Name: Anonymous 2009-10-28 10:53

You can implement exception handling unportably in C, as long as you can write some assembly code for your platform.

Name: Anonymous 2009-10-28 10:59

>>83-85 I feel I'm being [spoiled]trolled[/spoiled].

>>71 said that I, personally, don't need smart pointers in C because "there's no such thing as exceptions". Being a professional C programmer, I was deeply offended by such a moronic statement.

Exception mechanism is merely a tool that provides one particular way for solving a certain class of problems. Not having this exact tool only means that I have to implement the solution in a slightly different way. I open a file, try to read something from it unsuccessfully and then need to close it before reporting error myself, with exceptions I put close in the finally block, without exceptions I make a "finally" label near the end of the function, close the file there, and set up return value and goto there whenever something fails.

The problem I'm solving is the same, the structure of the solution is roughly the same, and only the thin layer of syntax and semantics of an actual language produces somewhat different implementation.

I'm greatly saddened by the stupidity and arrogance of >>71,83-85, who not only can't see beneath that superficial layer, but are entirely convinced that there is nothing at all beyond that.

Of course I'd need more than one logical exit point in a function if it can fail somewhere. Of course I'd have to map these onto the real exit point(s) somehow and clean up all resources, and why the fuck anyone would think that 'throw' is somehow different from 'return' in this respect? Of course I would appreciate RAII greatly while I'm at it.

Name: Anonymous 2009-10-28 11:39

>>89
Stopped reading at you claiming to be offended by a moronic statement. You should by now know (if you lurked long enough, that is) that every post here contains at least 75% moronic content.

Name: Anonymous 2009-10-28 13:00

>>90
(if you lurked long enough, that is)
Non-moronic content.

Name: Anonymous 2009-10-28 13:03

>>89
RAII
Stopped reading there.  Did you mean RAF?

Name: Anonymous 2009-10-28 13:06

>>90
Of course I was not deeply or at all offended, you moron. It's a polite figure of speech that substitutes for "I'd rip your filthy tongue out and made you swallow it if I were unfortunate to listen to your bullshit in person". The kind of thing you do to people who are trying to offend you (unsuccessfully, of course).

Name: Anonymous 2009-10-28 13:36

lol RAII hacks.

I'll take my WITH- macros and UNWIND-PROTECT instead.

Name: Anonymous 2009-10-28 18:07

>>82
>>89

Not having this exact tool only means that I have to implement the solution in a slightly different way. I open a file, try to read something from it unsuccessfully and then need to close it before reporting error myself, with exceptions I put close in the finally block, without exceptions I make a "finally" label near the end of the function, close the file there, and set up return value and goto there whenever something fails.
...So you're saying compiler exception support is superfluous and unnecessary? Are you trying to prove my point here? What was your point again?

Of course I'd need more than one logical exit point in a function if it can fail somewhere. Of course I'd have to map these onto the real exit point(s) somehow and clean up all resources, and why the fuck anyone would think that 'throw' is somehow different from 'return' in this respect?
Nice job shithead. You don't seem to understand that the point of exceptions is that they propagate through many functions on the stack. Smart pointers and RAII aren't syntactic sugar for goto cleanup; they are syntactic sugar for longjmp and a thread-local cleanup stack (and in many compilers that's exactly how they're implemented).

This is why smart pointers aren't needed in C. Unless you're using a library that actually longjmps (like libpng), there's no danger that some exception will propagate through your function; unless the thread aborts your 'goto cleanup' will always be called, so it's sufficient to cleanup resources.

(And this is entirely unrelated to the issue of reference counting, which is often conflated with smart pointers; lots of C libraries use reference counting).

You never programmed anything remotely complex in C, I guarantee that.

Hilarious, from one professional C programmer to another. Ask the Linux kernel devs what they think about exceptions and smart pointers.

Name: ​​​​​​​​​​ 2010-10-24 18:12

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List