- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
With what?
Admin
http://www.youtube.com/watch?v=gvdf5n-zI14
Admin
More likely this: http://en.wikipedia.org/wiki/Advanced_Debugger.
Don't think Java produces core dumps.
Admin
Admin
Admin
At least Vince knew how to practise safe hex.
Admin
The flip side is that problems show up when building for release because the program was relying on some integer to be initialized to 0 or some boolean to be false implicitly.
Admin
Admin
Who hasn't done a thing like this?
Admin
Zero is, in fact, the worst possible arbitrary polluting fill value, as it creates valid-looking uninitialised variables, while seeing a long full of 0xCCCCCCCC (or any other always-the-same byte) is a dead giveaway.
Admin
I would have gone with "If you'd prefer not to have to fax over a core dump, feel free to call the PM and tell him that he's an idiot."
Seriously, the customer should thrown around his weight at that point.
Admin
Admin
"I"s of course, every variable should be initial "I"sed.
Admin
With Zed
Admin
Or worse, the variable is a pointer (assuming an architecture where NULL is an all-zeroes bit pattern), and you do something sane-but-specific with NULL, but dereference non-NULL immediately and therefore crash if the poison value is something guaranteed to create invalid pointers (in the sense where NULL is not invalid).
The point is to make it easier to detect these errors during development, as poisoning values is costly at run-time.
And yes, indeed, zero is an all-same value. I should have been more specific.
Pop quiz: why is 0xCC a good value?
In Win32 user-space, addresses above 0x7FFFFFFF (0xBFFFFFFF in a /3GB machine) do not map to readable memory, much less writable. 0xCCCCCCCC is therefore guaranteed to cause a segfault (most likely actually an invalid page fault, but never mind) when dereferenced.
Admin
Which is why it's a good value, I guess...
Admin
Admin
BTW- What do you normally initialize pointers with (when not assigned an actual value)? The correct answer is... NULL! Should I go ahead and redefine NULL as 0xCCCCCCCC? You also haven't address the fact that by only initilizing undefined variable in debug mode, you are opening up a major can of inconsistent worms.
Admin
And the correct "doesn't point to anything" value for pointers is indeed NULL, and that NULL is the value given in the compiler / library, not some arbitrary invention.
And the inconsistent worms arise in release mode where the poisoning is not done (because it causes glacial performance on a good day), so pointers will occasionally have accidentally-sane values. By running in debug mode and, you know, testing the software, you find the uninitialised code paths.
Having a compiler that can detect such things and warn you about them helps as well. GCC (spit) is not that compiler, because historically it only did that analysis in full-on optimising modes...
Addendum (2011-10-12 11:11): (*) It is more correct to assign values before use rather than initialising the variable at definition - in some cases when using C89 you cannot assign real values at definition because you have no way to calculate them until later. In such cases you have three choices: you use an extra brace-block to create a delayed definition, or you initialise with an arbitrarily-selected value solely to have an initialised variable, or you leave the variable uninitialised until the assignment.
Admin
Admin
Good one.
And for people who like to talk shit about C, please remember it is the only language that will still exist twenty years from now, because unlike Java, C#, ruby and others it meets its objectives : simple ASM translation - all others having various amount of fail and fancy stuff built-in, but none ultimately filling a purpose.
Java will die because it's slow (anything slower than C++ is slow), heavy(private static final ultimate final again var of doom var1=0;), useless on Windows (no comment), and overall as Johnny said, the best way to create clueless programmers by protecting them from their major mistakes and misunderstandings.
C++ will die because it's not modern enough and it's quite realistic to imagine a "better" C++.
Countless others will die . but C will remain - unless anyone has a better idea of a programming language that is as efficient as C ?
Admin
Admin
Admin
tl;dr summary of this page:
Java will DIE during slow initializing with zeroes instead of 0xCC
Admin
Admin
Admin
If the compiler always automatically initialises every variable, then much of the time the variable will get initialised twice - once by the compiler to %default-value%, then again by the programmer to the value they actually want. This is quite expensive!
The worst case is things like:
Now you can of course build a compiler that avoids double-initialising in these trivial cases where the programmer's initialisation is instant and a constant.What about other cases, like initialising to the result of some function call? (For example a constructor)
Should the compiler initialise the variable before calling the function? What if the programmer makes a mistake and uses the variable during that initialisation function call?
As you said, you can have a design rule for your programmers that says "Thou Shalt Initialise Everything".
Good idea - but how do you enforce that rule? Simple code review is not going to spot it in all cases - just the most obvious.
So, how about a special compiler mode that automatically initialises every variable to a particular magic number? It'll run noticably slower than the normal code, but you can test (and unit test) with it and you don't need the compiler to be very clever about it.
That way, if you ever see that magic number anywhere you can immediately raise an alarm and check whether it's a genuine value or a screwup.
To minimise false alarms and speed up checks in unit tests etc you'll want to pick a magic number that's easy to spot, unlikely to happen in 'normal running', and that will instakill the application if ever dereferenced.
Admin
while( 1 ) { /* loop that really is meant to run forever */ }
One compiler for 8088 that I used many moons ago used a severely suboptimal optimiser. On its most aggressive setting, it translated the above code as:
JMP bottomOfLoop topOfLoop: ; ; loop that really is meant to run forever ; bottomOfLoop: MOV AX, 1 CMP AX, 0 JNE topOfLoop
I threw the compiler out, needless to say, and replaced it with another one which performed a group of vaguely complicated FP calculations in a third of the time.
FORTRAN, by-the-way, is also plagued by aliasing in various unpleasant and hard-to-detect ways.
Is the simplest example. If you only have the code for F, you cannot possibly know that it will suffer from aliasing problems. Allowing EQUIVALENCE makes it that much harder to detect.
On the other hand, I seem to recall some blither somewhere about aliasing being marked as provoking undefined behaviour in FORTRAN, so maybe it doesn't matter.
Admin
CAPTCHA points out that he sees no way for the virus tego through the fax machine.
Admin
int i;
i is not initialised to anything in particular. Visual C++ has a bug-detection aid in debug mode where each function essentially begins:
Admin
Admin
Admin
C is dead same way as FORTRAN.
There are some legacy code of course, but it will be eventually replaced with C#
As in operating systems (Cosmos, Singularity) and embedded (.NET Micro Framework)
Admin
2/10 - Too obvious (people don't usually bite for the stupid ones)
Addendum (2011-10-12 12:14): What you could do next time for more internets is to go slapstick: say something like "it will be eventually replaced with Ruby or ColdFusion"
Admin
Yes, but these don't impact optimization: FORTRAN simply optimizes as though there were no aliasing and if you introduce any it's your problem to get it right.
Admin
Admin
Here in Hyderabad, "taking dump" is youfamisim for defacation.
Admin
Admin
I don't know; I always thought 0xDEADBEEF was cool.
Admin
VB.NET is obvius going to stay.
Admin
Admin
This is mad, makes me want to murder someone.
Admin
Admin
Admin
the glittery unicorn ponies are especially corny.
Admin
Here it's a euphemism for going to Hyderabad.
Admin
This Websense category is filtered: Freeware and Software Download. Sites in this category may pose a security threat to network resources or private information, and are blocked by your organization.
Admin
Admin
No, you are wrong. if less knowledgeable programmers are being created, the culprit is not languages like c# or java, it is some teacher that insists on too much teory and low practice. teory without pratice is futile, pratice without teory is leaky. will they insist on this disbalance, will he have more and more clueless people.
The problem is not with pointers, i have learned them from C, but my main language was basic, and it saved me from much problems when p/invoking (using API was considered black magic, and i were a magician, because i understood pointers, i have no problems with Win32). Even now, using csharp, it saved me from disposable problems when using "native" wrapped dotnet classes.
Admin
ps, now i write a lot of C/C++, and have no problem with pointer. i even do some assembly just for fun.