how to delete **char ?!?

Started by
11 comments, last by silvermace 19 years, 4 months ago
Quote:Original post by iMalc
e.g. Try it without the do while(0), or also without the {}, inside multiple levels of if-else statements. You'll find that there will be special cases where you have to leave off the semicolon for example, to get it to work right where you otherwise would just write it normally.


A fast Google gives lots of hideously ugly code examples. My personal convention is to always have such macros take care of their own semicolons when needed, and no stand-alone macro is ever terminated by a semicolon in code. I find this much easier to read, which is probably why I've never had to bother with a do {} while(0) wrapper. Personal preference I guess.


Quote:Original post by iMalc
Dubbing in relase mode is infinitely easier if you turn optimisations off too etc, so what's your point? If you gotta do it, you gotta do it.
The whole point is that you will have picked up any errors of this kind in debug build before you switch to release build. You should have no remaining assert failures and have tested each execution path in doing code coverage. Sure, problems can appear only in release or only in debug, but it shouldn't be this kind of bug as you would have eliminated them already.


Your utopian concept of all bugs being corrected in debug builds is nice and lovely. I, however, live and code in the real world. If a customer calls and complains that his software just crashed with a pointer exception at 0xBAADF00D I know instantly what is wrong - my code, accessing released memory. I can find and correct the problem often with only a short time of investigation. On the other hand, if they report some random memory address, I have a lot more work to do. If the bug only manifests itself in certain compiler setups, debugging can be a total nightmare. Turning off optimizations and/or returning to debug builds is, in a lot of cases I work with, not an option.



Quote:Original post by iMalc
So why do they turn off clearing blocks to 0xCCCCCCCC for example, in release build then? It's because you've found and fixed any bugs that it would help you find. If a bug of that nature is still present in your release build, clearing the pointer after use certainly isn't going to make your exe run any better, so why bother? The overall increase in speed and decrease in exe size might be small, but some people like it.


I doubt it. The real reason is far more likely related to performance. If I deallocate a 300KB slab of memory, setting every word to some "cleared" value is performance intensive and likely wasted. Of course you could do something like only clear allocated memory blocks of less than a certain size, but this becomes questionable and somewhat unreliable behavior for developers to work with.

Again, I wish your youthful dream of having all bugs fixed in release software were true, but I have to live with real life instead. More's the pity, because it's a very warm, fuzzy dream [wink] Of course clearing the pointer won't make execution any more stable, but it will make the job easier for developers to come back to and fix as needed.

Really the issue for me isn't the specific case of not clearing pointers when deallocated. The issue that I see here is a programmer who doesn't appreciate the benefits of designing code that is easy to debug and maintain in any scenario. It's not the specific example here, it's the underlying mentality.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement
Quote:Original post by ApochPiQ
Your utopian concept of all bugs being corrected in debug builds is nice and lovely. I, however, live and code in the real world. If a customer calls and complains that his software just crashed with a pointer exception at 0xBAADF00D I know instantly what is wrong - my code, accessing released memory. I can find and correct the problem often with only a short time of investigation. On the other hand, if they report some random memory address, I have a lot more work to do. If the bug only manifests itself in certain compiler setups, debugging can be a total nightmare. Turning off optimizations and/or returning to debug builds is, in a lot of cases I work with, not an option.

You're missing out the fact that if it's a large product (and in my case it is), then it doesn't matter much that you know it crashed with a BAADF00D pointer, as that wont in itself help fix the bug. In most cases the thing that helps most is knowing exactly what they did (so that you know where in the code to look), and/or getting their configuration files, and/or getting a minidump (which our company makes good use of as they are very useful). I work at a decent sized software company and find that bugs only showing up in certain configurations are very rare ... 1% or less kind of rare. If you're finding it worse than that then maybe you are using a dodgy compiler. I very much live in the real world thankyou.

Quote:Again, I wish your youthful dream of having all bugs fixed in release software were true, but I have to live with real life instead. More's the pity, because it's a very warm, fuzzy dream [wink] Of course clearing the pointer won't make execution any more stable, but it will make the job easier for developers to come back to and fix as needed.

I never said anything about all bugs being fixed in release builds, but that if you have a problem then you can easily go back to your debug build and reproduce it there as well (where it is always going to be easier to find and fix). Don't you ever switch between the two? I believe that both should always run fine, so they should be used for their respective purposes. We regularly make use of both.

Quote:Really the issue for me isn't the specific case of not clearing pointers when deallocated. The issue that I see here is a programmer who doesn't appreciate the benefits of designing code that is easy to debug and maintain in any scenario. It's not the specific example here, it's the underlying mentality.

On the contrary, the code I write is very easy to debug and maintain. More so than someone who's code needs to be debugged regularly using a release build, perhaps because the debug build might be broken? If you can track down the cause of a bug from a debug build (which you can 99% of the time) then you wouldn't use a release build to do so would you? It'd be like going in with one hand tied behind your back! (Just try it in .NET!!!)[smile]

I'm very good and fast at debugging code, in fact I spent 3 years in a dedicated "product support" group who's main responsibility is maintaining and bug-fixing others code.
What I see is someone who writes code very defensively (which is a bad thing according to the book "Writing solid code", which have you read btw?), and doesn't make appropriate use of debug vs release builds.
My underlying mentality is no more wrong than yours. Different yes, but wrong No.

My apologies for contribution towards turning this thread into an argument.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Quote:Your utopian concept of all bugs being corrected in debug builds is nice and lovely.
Your utopian concept of taking imalc as a noob is nice and lovely too. i dont think he ever states any truth to this beyond "it will help find bugs faster" and he's quite simply right. weather you set the pointer to 0xBAADF00D or not makes very little difference, the program still crashed.

Quote:Your utopian concept of all bugs being corrected in debug builds is nice and lovely. I, however, live and code in the real world. If a customer calls and complains that his software just crashed with a pointer exception at 0xBAADF00D I know instantly what is wrong - my code, accessing released memory. I can find and correct the problem often with only a short time of investigation. On the other hand, if they report some random memory address, I have a lot more work to do. If the bug only manifests itself in certain compiler setups, debugging can be a total nightmare. Turning off optimizations and/or returning to debug builds is, in a lot of cases I work with, not an option.
personally id rather not rely on comedic pointer addresses to trace my bugs, i like to use exceptions and logging. just personal preference though :)


Quote:I doubt it. The real reason is far more likely related to performance. If I deallocate a 300KB slab of memory, setting every word to some "cleared" value is performance intensive and likely wasted. Of course you could do something like only clear allocated memory blocks of less than a certain size, but this becomes questionable and somewhat unreliable behavior for developers to work with.
this is moot, we have already noted that these "tricks" are not used in release mode.

Quote:
Really the issue for me isn't the specific case of not clearing pointers when deallocated. The issue that I see here is a programmer who doesn't appreciate the benefits of designing code that is easy to debug and maintain in any scenario. It's not the specific example here, it's the underlying mentality.
your flaming him for not setting his deleted pointers to 0xBAADF00D, wtf.

you say code that is "easy to debug and maintain in any scenario." and yet you claim to live in the real world...

EDIT: i'm sorry if this comes across flamey, i get excited when i discuss :)

Cheers
Peace Out,
Danu
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website

This topic is closed to new replies.

Advertisement