- 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
No it isn't.
char name[]; name = NULL;
Result: syntax error
char *name; name = NULL;
Result: success
Think of an array as like a reference. Yes, under the hood its a pointer, but the address it points to can't be changed and can't be null. Just like a reference to a value.
Admin
Did you know you can only next if-else statements 256 deep in visual studio? I know and it isn't because of some fact I ran across in the manual.
Admin
Yeah, dats PascalCase not camelCase! Alternatively, Win32Case.
Admin
Admin
Admin
I'm guessing something like:
This won't overwrite the buffer but it's still has a huge problem, in particular for large magnitudes, losing the least significant digits will effectively divide by ten, one hundred, one thousand, etc.
Admin
Admin
People that post even when they don't know the difference between a compiler and a linker are another WTF too...
Admin
Knowing Bruce, I should point out here that this used to be known as "Spaceship Code" for precisely that reason!
Admin
What if you passed 1000000001? It wouldn't trip any of the if cases so you hit the end of the function without modifying NinecharString: I'm assuming this is a story-telling bug...
Admin
Admin
The file went from this system into another, and for "whatever" reason, the other system (which was not written by the company Bruce works for BTW) accepted the output of the existing program (except the nulls, which was the bug causing the problem in the first place).
In fact, if he had written it differently, it's quite possible that the back-end would also need to be re-written - at the customers expense.
PS: The file format used was also produced by another device, and the file format the code produced had to match that to a tee. The previous device sent data over a serial cable at slow speed, so you can see why the format was chosen, as the customer wanted to re-use the existing back-end. That's why the fields are all fixed length, there are no delimiters, etc.
Admin
The way some 0 Number); instances are missing a comma, that would separate 0 from Number and match the number of formatting directives, is actually cute.
Apparently someone actually typed each instance manually, so CopyAndPasteProgramming was not used. Really cool! :)
Admin
This code makes me think of The Dreadnaught Factor
Admin
Admin
Activating pedant mode: The counterpoint of "you name in" is "I name in", not "my name in" (that's the counterpoint of "your name in").
Admin
It is not precisely equal, try using sizeof on these babies:
Admin
I suspect most people that use IDEs don't know the difference between compilers and linkers. These new-fangled tools will never catch on :-)
Admin
Well the linke could certainly detect the collisions because there would be multiple symbol definitions with the same 32 char name. It could then just emit an error such as "multiple definitions of symbol %s", with a list of the object files containing such definitions, and (what the hell) line numbers harvested from the debug data.
The real WTF was the comment that Bruce's code "worked the same way", I hope this doesn't mean that bruce produced an if-else ladder too. I can think of two alternatives to embed minus signs in the numbers ... void ConvertLongToString(char NinecharString[], long Number) { int c,w; char * zeros="00000000"; c=(Number<0); /(Number<0)?1:0;/ for(w=Number;w;w/=10)c++; if(c<10) snprintf(NinecharString,9,"%s%ld",zeros+c,Number); else snprintf(NinecharString,zeros); /*safer than it looks;-) */ }
Or void ConvertLongToString(char NinecharString[], long Number) { int c; c=snprintf(NinecharString,9,"%ld",Number); if((c<0)||(c>9)) { sprintf(NinecharString,"000000000"); } else if(c) { memmove(NinecharSring+c,NinecharString,9-c); while(c--)NinecharString[c]='0'; } } Depending on your aversion to division or function calls.
If you have an aversion to pointer arithmetic you shouldn't be coding C.. oh hang on, Fred was still trying to believe in Strings, he shouldn't be coding in C anyway.
Admin
Actually I meant else if (c!=9) WTF insomnia
Admin
Admin
Admin
Interesting code.
Does anyone get paid by the line these days? I thought that sort of practice had long since been retired.
Admin
Who the fuck are you.
Admin
Admin
If you want to know where code like this comes from, and why it's still being done today, look no further than the asp.net forums:
http://forums.asp.net/t/1416271.aspx
Admin
The grossest bug is that, if you give it a value over one billion, it doesn't put anything at all into NinecharString. Hey, we get an ASCII text file with an embedded core dump! Neat! Hard on the reader, though.
Admin
My 50ct:
sprintf(NinecharString, "%09ld", Number); if (Number < 0 && Number > -10000000) // Move minus { int i; for (i = 1; i < 9; i++) if (NinecharString[i] != '0') break; NinecharString[0] = '0'; NinecharString[i - 1] = '-'; }
Admin
I knew that. It's really annoying, but there are workarounds...
Admin
The true WTF is you don't know WTF you are talking about. It's not php, it's C RTFA
Admin
This joke was shit
Admin
I think this article was written by a Springsteen fan... "Bruce" got a call from "the Boss" ? :)
Admin
Wow butchering c# and English at the same time, that's the efficiency you can only get from a "large, cheap, well educated work force"
Admin
Does it work in a multi-freded-environment?
Ha, ha.
Admin
"its great to work in .net platform and if else is a very useful tool provided by it."
So they never encountered any other platform that provided if else. Geez. And those people build websites! Oh man. But the biggest WTF is the entry by the fool who tries to educate them, at the end. What a waste of breath that is.
Admin
To be fair I think the last guy was a troll who was just showing off some of c#'s features.... over and above the earth shattering "if else" feature. Someone had already suggested using an array of strings lookup. I'd love to see those guys CVs though. "I has five year of c-hash experiences."
Admin
When a compiler/linker suite has an identifier name limit, it can't recognize collisions because it's not storing the entire identifier name.
Admin
Admin
I once had an extended argument with someone who insisted that he wrote his C code in a compiler.
Nothing I said could convince him otherwise.
Admin
It could still produce an error along the lines of "redefinition of existing symbol 'foo' at file2.c line 1234 (previous definition: file1.c line 123)", and leave it up to the programmer to figure out what the actual identifier names are beyond the 32 characters which got printed.
If there's some reason why that wouldn't work, I'd be interested to hear it.
Admin
Admin
Was he working in a language that compiled to C as an intermediary language?
Admin
The program isn't storing the entire identifier name, no.
It's storing the first 32 characters.
The behaviour I'm expecting/describing is roughly (semi-pseudocode):
In other words: when the program sees a symbol being defined, it should be able to compare that against its list of "known defined symbols", and if - as here - 32-character string is already in its list, say "hey! we have a collision!" and take appropriate action.
Just because it can't tell that the beyond-32-characters part makes it not a collision doesn't mean it can't detect a collision within those first 32 characters...
If there's more to it than that which would provide another pitfall, you'll need to be more specific, because I'm not seeing it.
Admin
Plus, IIRC he was talking about opening up his source file in a compiler to edit it...
Admin
I guess I misunderstood the suggestion. Carry on.
Perfect example of taking the platform for granted. ("Whoa, so you're saying that the compiler is a program too?")Admin
One has to try.
:)
Admin
Exactly, if two symbols longer than 32 chars collide, then the abbreviated forms will also collide.
UNLESS You mean that as each symbol is read from an object file it's full name is looked up in the symbol table being generated, and then it's truncated before being stored... In which case the linker's own code is a WTF, quite clearly because of it's own internal inconsistency. Some object file format or code generator that consistently truncates symbol names however does not make collision detection impossible.
I've come across the "Truncation causes collision" issue a number of times, but I've never had any trouble coding to detect it!
Admin
gcc will not take char[] as a type in either C or C++. It's perfectly good Java though :-)
Admin
Admin
Surely ConvertLongInToString(char NinecharString[], long Number) is more expressive.
or clits(char NinecharString[], long Number) if that's just too long for you.