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

Pages: 1-

The problem with stackoverflow.com

Name: Anonymous 2010-06-06 7:54

And most other programming communities, really. (♥ /prog/)

http://stackoverflow.com/questions/2425728/delete-operator-in-c/
Question:: What is the difference between delete and delete[] operators in C++?

stackoverflow.com answer:
The delete[] operator is used to delete arrays. The delete operator is used to delete non-array objects. It calls operator delete[] and operator delete function respectively to delete the memory that the array or non-array object occupied after (eventually) calling the destructors for the array's elements or the non-array object.

The following shows the relations:

typedef int array_type[1];

// create and destroy a int[1]
array_type *a = new array_type;
delete [] a;

// create and destroy an int
int *b = new int;
delete b;

// create and destroy an int[1]
int *c = new int[1];
delete[] c;

// create and destroy an int[1][2]
int (*d)[2] = new int[1][2];
delete [] d;


For a new that creates an array (so, either the new type[] or new applied to an array type construct), the Standard looks for a operator new[] in the array's element type class or in the global scope, and passes the amount of memory requested. It may request more than N * sizeof(ElementType) if it wants (for instance to store the number of elements, so it later when deleting knows how many destructor calls to done). If the class declares an operator new[] that additional to the amount of memory accepts another size_t, that second parameter will receive the number of elements allocated - it may use this for any purpose it wants (debugging, etc...).

For a new that creates a non-array object, it will look for a operator new in the element's class or in the global scope. It passes the amount of memory requested (exactly sizeof(T) always).

For a delete[], it looks into the arrays' element class type and calls their destructors. The operator delete[] function used is the one in the element type's class, or if there is none then in the global scope.

For a delete, if the pointer passed is a base class of the actual object's type, the base class must have a virtual destructor (otherwise, behavior is undefined). If it is not a base class, then the destructor of that class is called, and a operator delete in that class or the global operator delete is used. If a base class was passed, then the actual object type's destructor is called, and the operator delete found in that class is used, or if there is none, a global operator delete is called. If the operator delete in the class has a second parameter of type size_t, it will receive the number of elements to deallocate.


Proper answer: The delete[] operator is used to delete arrays. The delete operator is used to delete non-array objects. Look it up in the documentation/FAQ/textbook/google.

Name: Anonymous 2010-06-06 8:52

NO EXCEPTIONS

Name: Anonymous 2010-06-06 8:55

/prog/ answer: Sepples sucks. Read SICP.

Name: Anonymous 2010-06-06 9:36

>>3
More succinct and more useful, even if the idiot asking the question might not realise that for years.

Name: Xarn 2010-06-06 9:50

The {spoiler /prog/} subreddit is located at http://www.reddit.com/r/Prague/ if you are unsatisfied with the questions posted on Stack Overflow.

Name: Anonymous 2010-06-06 9:54

>>5
I am satisfied with the answers poasted at /prog/.

Name: Anonymous 2010-06-06 9:55

THE_REAL_XARN is not the real Xarn, is he?

Name: Anonymous 2010-06-06 10:12

Why is there need for two operators?

Name: Anonymous 2010-06-06 10:13

>>7
Xarn doesn't have a Reddit account.

Name: Anonymous 2010-06-06 10:14

>>3
Actually I thought about it a little more.
The /prog/ answer: HAX MY ANUS!

Yes, that seems more like /prog/.

Name: Anonymous 2010-06-06 10:22

>>10
Upset because we wouldn't give your PHP question the light of day? /prog/ is by far the most helpful (genuinely helpful, not the worthless pussy-footing inoffensiveness idiots often mistake for helpful) programming community around, but we don't have a lot of patience for dumb questions.

Name: Anonymous 2010-06-06 10:29

>>11
who cares? Cant we just exist and give up with this retarded shit?

Name: Anonymous 2010-06-06 10:55

>>11
I'm both >>10 and >>3­. There's been an abundance of X MY ANUS for the past few months.

Name: Anonymous 2010-06-06 11:02

>>13
And it's beautiful, I'm sure you will agree.

Name: Anonymous 2010-06-06 11:03

[b]ABUNDANCE PAST MY ANUS[/b]

Name: >>15 2010-06-06 11:04

No more alcohol for me in the morning.

Name: Anonymous 2010-06-06 13:53

>>16


{i.....{b  Taro}-kun?}

Name: Anonymous 2010-06-06 14:26

>>17
No space after the {i function, and five function composition operators with no additional functions passed. That SexpCode is horribly formed, and while any parser would break, a good parser would go one step further to eat you up and spit you out, and you'd deserve it. You miserable failure.

Name: Anonymous 2010-06-06 14:31

>>18
This is why \b\i{\u{Penis}\o{Code}} is superior - whitespace isn't significant.

Name: Anonymous 2010-06-06 14:41

>>19
I think you are confusing significant with necessary.

Name: Anonymous 2010-06-06 15:16

>>19
What's your syntax for argument passing?

Name: Anonymous 2010-06-06 15:36

>>21
\url{http://my.an.us/}{My Anus}
Perhaps.

Name: Anonymous 2010-06-06 15:42

>>22
That's one more character than the equivalent SexpCode, and you need to use the Shift key more often.

Name: Anonymous 2010-06-06 15:55

>>23
Whoa, you got me there! Damn. That thing I hadn't thought of until you mentioned it because it doesn't exist on /prog/ (forcing me to make it up on the spot, complete with disclaimer), that I was going to use as final design, is far too bloated. That whole extra character will crash the servers!

\o\u\pre{  I'll just leave then, along with my leading whitespace.}

Name: Anonymous 2010-06-06 16:26

>>24
{o.u.tt   I don't think you've actually read the SexpCode spec or looked at the reference implementation.}

Name: Anonymous 2010-06-06 16:29

>>25
I think you're just looking to pick nits.

Name: Anonymous 2010-06-06 16:46

>>26
If you're going to try to posit some language as obviously superior to another one, make sure it actually is.

Name: Anonymous 2010-06-06 17:07

>>27
In >>21, you were quite clearly looking to trip me up. I don't care about "passing arguments" because I'm not sure markup really needs arguments, and stuff like URLs kind of already link themselves (http://hey.look.at/me.html). This inside-out sexpcode was intended as a replacement for the BBCode we all know and love, where whitespace is unnecessary.
That method of ``function composition'', frankly, looks horrible and adds clutter to the language. The same goes for ``iteration'' - why add another operator in? Why can only certain functions be iterated? What's wrong with {sup.sup }? BBCode was supposed to make markup simple, but sexpcode goes against this.

Plus, I remember seeing some other kind of markup like \b{this} somewhere, or something, way before I originally posted it. Just to say that it is useful and it works.

Name: Anonymous 2010-06-06 17:22

>>28
whitespace is unnecessary
Replacing whitespace with more characters that are harder to type isn't an improvement.

Why can only certain functions be iterated?
I'd like to hear your explanation of why [b][b]this[/b][/b] should make sense. The functions that can be iterated can be iterated because their repeated application actually produces different results. The others won't generate a syntax error if you try to iterate them, but they'll only be applied once.

What's wrong with {sup.sup }?
Nothing, if you enjoy repeating yourself. That syntax is a perfectly valid alternative.
At that point you might as well complain about the concept of function composition too, because you can nest things anyway.

BBCode was supposed to make markup simple, but sexpcode goes against this.
BBCode was supposed to make sanitizing input simpler for people running websites that take user comments (which it didn't, really). If it did anything for the end user it was unintentional. SexpCode is supposed to make mark-up powerful and less error-prone, which it does.

Plus, I remember seeing
There are hundreds of mark-up languages based on genuine S-expressions like SexpCode.

You're just upset because Xarn actually got off his ass and implemented something, and is now getting attention for it. Grow up.

Name: Anonymous 2010-06-06 17:48

>>29
You're rather more upset and are just perpetuating this. I am rather enjoying your tactical avoidance. Let's begin, anyway.
Replacing whitespace
Oh, so it's about being easier to type now? What about being easier to make mistakes? See how this conversation began.

why [b][b]this[/b][/b] should make sense
I'm glad you picked [b]. Let's have a look at some CSS.
p.normal {font-weight:normal}
p.thick {font-weight:bold}
p.thicker {font-weight:900}

Every extra [b] could easily add 100 to the font-weight without using deprecated HTML such as <b>.

you might as well complain
You might as well twist it so that it appears that I am.

Xarn actually got off his ass and implemented something
He didn't really need to. BBCode works just fine. This just appears to be a hobby project.

Grow up.
This one's pure gold. Are you implying jealously? What attention would I get if I did something? If I wanted attention, I'd give myself a name and set up a blog documenting a load of FIOC toy programs I'd have written. But no, I'm completely anonymous. To a bystander, we could be the same person. You wouldn't be able to identify me in a different thread.

The amount of typing here has increased exponentially. It's also my bedtime.

Name: Anonymous 2010-06-06 18:12

>>30
At this point your whining doesn't have any bearing on reality anymore, and you're just flailing desperately. Goodbye.

Name: Anonymous 2010-06-06 18:36

>>30
Cool trollan, bro.

Oh, so it's about being easier to type now?
It's always about being easier to use. That's the only significant difference between Python and C and Haskell and COBOL and Sepples and Java.

What about being easier to make mistakes?
What about it? You haven't actually demonstrated that it's easier to make mistakes in SexpCode than in your knock-off. Since every modifier key that needs to be pressed increases the odds of typos, I'd say the advantage here isn't with your language.

I'm glad you picked [b]. Let's have a look at some CSS.
Your suggestion would violate the user's expectations of how bold text works. BBCode doesn't work like that, Markdown doesn't work like that, and if you weren't grasping at straws and actually got off your ass to make your knock-off work, your language wouldn't work like that either.

You might as well twist it so that it appears that I am.
Do you know what analogy is?

He didn't really need to. BBCode works just fine.
Pretty much everyone disagrees. Just look at the amount of BBCode failures right here in the Mecca of BBCode mastery to see how inadequate BBCode is.

This just appears to be a hobby project.
So?

This one's pure gold. Are you implying jealously?
It oozes from your every word. If you were motivated by anything else, you'd actually try to engage in constructive criticism instead of just waving your arms and spouting bullshit.

It's also my bedtime.
Sweet dreams.

Name: Anonymous 2010-06-06 19:09

>>32
Fuck off, `` Xarn ''.

Name: Anonymous 2010-06-06 19:26

>>24,28,30,33
Sure is summer in here.

Name: Anonymous 2010-06-06 19:36

That's the only significant difference
[i]Citation needed.

every modifier key that needs to be pressed increases the odds of typos
Citation needed.

Your suggestion would violate the user's expectations of how bold text works.
Original research?
"Bold Text" does not necessarily describe just one of potentially many weights that can belong to a font family.

Pretty much everyone disagrees.
Citation needed.
Relevance?
BBCode and SexpCode do the same task in virtually the same way; a true improvement would involve a UI and hotkeys, rather than yet-another-mixin-syntax.

It oozes from your every word.
Citation needed.

Conclusion: Your post is so full of shit. And I'm not >>30-san, just an innocent bystander.

Name: Anonymous 2010-06-06 19:45

>>34
[blue]>>>/b/[/blue]

Name: Anonymous 2010-06-06 20:13

>>35
My palm is on my face right now.

Name: Anonymous 2011-02-03 0:04


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