- 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
My best guess would be that what we're looking at is the preprocessor output of a .C file.
ok
dpm
Admin
Well, with a few assumptions on the names of some constants and functions, this code looks quite sensible, but without context and knowledge of the data stored in the sysobjs[], we will never know. I think this code was somehow generated, so I think it is not really a WTF, however, the knowledge about its generation process seems to be lost at the submitting source of this WTF.
<font style="color: rgb(0, 0, 255);" size="2"> public static final int BASE = 0x00000032;
public static final int REFERENCE = 0x0000004e - BASE;
private static final int SEQUENCE = 0x0000004a - BASE;
private static final int SIMPLE = 0x0000004d - BASE;
private static final int BIT4 = 1 << 4;
private byte getReference(int index) {
return sysobjs[index * 8 + 1];
}
private byte getType(int index) {
return sysobjs[index * 8 + 2];
}
private byte getBits(int index) {
return sysobjs[index * 8 + 3];
}
private byte setPccoLv(int index, int value) {
return sysobjs[index * 8 + 0] = (byte) value;
}
private byte getValue(int index) {
return sysobjs[index * 8 + 5];
}
private byte setValue(int index, int value) {
return sysobjs[index * 8 + 5] = (byte) value;
}
private void adjustNegativeValue(int index, int adjustment) {
byte tmp = getValue(index);
if (tmp < 0)
setValue(index, tmp + adjustment);
}
void RstPccoLv(int curIdx) {
if ((getType(curIdx) == REFERENCE) && (getReference(curIdx) > -1)) {
setPccoLv(curIdx, 0);
int refIndex = getReference(curIdx);
adjustNegativeValue(refIndex, 4);
if (getType(refIndex) == SIMPLE)
setPccoLv(curIdx, (getBits(curIdx) & BIT4) == 0 ? 0 : 1);
else if (getType(refIndex) == SEQUENCE) {
setPccoLv(refIndex, 0);
refIndex++;
if (refIndex < nbObj) // bug: should be tested in while
while (getType(refIndex) == SEQUENCE)
setPccoLv(refIndex++, 0);
}
}
}
</font>
Admin
"This was probably (originally) machine-generated code and never meant for human maintenance."
My machine resents your implication that it would ever generate a WTF like this.
Admin
The movie for the quote.. eart Of Darkness.
Admin
You've got your own WTF in your comments. Writing "when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b" tells us nothing, because it's simply stated again below: " if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b)"
Admin
Not hardly. Check some C# that was written by hand against some C# written with a designer program (e.g Visual Studio).
Hand written code is spaced out and well indented and sparse, and machine generated code is dense and ugly, and contains tons of extra crap methods. Uuuuugly.
Admin
<FONT face="Courier New" size=2>i'm pretty sure both machines can't add.</FONT>
<FONT face="Courier New" size=2>ah, that was the dyslexia talking. rather, 4:(100) & 1:(001) = 5:(101) ; jah? or, if you wish, 5:(101) xor 1:(001) = 4:(100). in any case, the machine can't add.</FONT>
Admin
Javac in general leaves most optimizations to the JIT compiler found in most VMs.
Admin
And even on the off chance that it can, I sure as hell wouldn't trust it to.
Admin
What is this bitmask bullshit everyone is spouting. 1+1+1+1 does not equal 7 (0x1111). It's a really lame obfuscation trick is all. The main code is just an amazingly messy way to use pointer arithmatic.
Except for what ends up here, of course. :p
Admin
I also think that this code is machine generated. Must be a stupid generator, though. Maybe it was writen in language where it is easier to create a 0+1+1+1+1 string than calculating 4 (because the language does string handling better than arithmetic). Prolog comes to my mind...
Admin
I think this person thought that binary 1110 = 1+1+1+0 not 18+14+12+01
Admin
WTF? WTFF is that???
Admin
Umm... 0x1111 is not 7.. I'm going to pretend you don't know that "0x" typically means hex (where 0x1111 = 4369), and that you think it means binary. If that were the case, 0x1111 would be 15, and 0x0111 would be 7..
And who claimed 1+1+1+1 was equal to 7 anyway?
Admin
Are you serious? That's a pretty big WTF right there. There is no way that loading two small constants and adding is going to be better in any way than loading one small constant. I think I'll stand by my comment: if javac will write out code to do 0+1 instead of just 1, it's brain dead.
Admin
A quick test reveals that it will optimize out some simple constant stuff. I've seen it ignore stuff like empty for loops however. That's where an obfuscator with a bytecode optimizer like Proguard comes in.
As for everyone trying determine where it came from, it came from a J2ME porting project. What it actually does is another matter entirely.
Admin
Oh I get it, it's the source code to SQL Server 2000, right?
Admin
True, but NOT this. Compile-time constant folding is REQUIRED by the Java spec to be done by any compliant compiler.
Admin
Wodies. Please get the quote right ;)
Admin
Event Horizon.
TODO list : dump this programmer in a black hole
Admin
It's not event horizon, that quote is
Admin
5 secs with google.com says Babylon 5.
Admin
5 & 1 is 1. See, if you can't get the most basic things right, why don't you just shut up? The other users will love you all the more for it.
Admin
It sounds like a line from Harry Potter (1), where he is buying his wand from Olivanders, and Olivander is talking about what Voldemort did with the wand that contains the other Phoenix tail feather.
Admin
I mean 4 & 1 is 0.
Admin
What kind of silly macro would produce this sort of crap?
Admin
I see no contradiction.
Admin
First thing I thought of when I saw this was "Typographical Number Theory". Perhaps the programmer had just finished Hofstadter's Godel, Escher, Bach and thought they'd give it a go in RL?
[N.B. In TNT, (see http://en.wikipedia.org/wiki/G%C3%B6del_numbering), you only have the number '0' and the operator 'successor to', hence '1' is 'S0', '2' is 'SS0', etc]
Just be glad (s)he didn't read a book on Lawsonomy (http://www.lawsonomy.org/Lawsonomy100.html), or the whole thing would be written in 'zig-zag and swirl'!
Admin
See, Alexis, if you can't get the most basic things right... :)
Admin
Ever tried to maintain code that is generated by parser generator?
Admin
It's certainly possible for the actual code to be non-silly.
For instance, what would ONE_DAY expand to, given the following directives?
#define ONE_SECOND 1
#define ONE_MINUTE (SECONDS_PER_MINUTE * ONE_SECOND)
#define ONE_HOUR (MINUTES_PER_HOUR * ONE_MINUTE)
#define ONE_DAY (HOURS_PER_DAY * ONE_HOUR)
ok
dpm
Admin
Missed pasting the first three directives:
#define SECONDS_PER_MINUTE 60
#define MINUTES_PER_HOUR 60
#define HOURS_PER_DAY 24
#define ONE_SECOND 1
#define ONE_MINUTE (SECONDS_PER_MINUTE * ONE_SECOND)
#define ONE_HOUR (MINUTES_PER_HOUR * ONE_MINUTE)
#define ONE_DAY (HOURS_PER_DAY * ONE_HOUR)
ok
dpm
Admin
I know :)
But I couldn't resist the mental visage of sending this programmer straight into enternal torment in hell.
Admin
visage = vision of course[:$]
Admin
Wrong:
cat X.java
public class X { public static int n = 10 + 20; }
javac X.java
javap -v X
static {}; Code: Stack=1, Locals=0, Args_size=0 0: bipush 30 2: putstatic #2; //Field n:I 5: return LineNumberTable: line 2: 0 }
Note: 10 + 20 is 30
Admin
Both results are correct (in case you didn't notice). I only decided to give emptyset the benefit of the doubt that he meant something else when he originally wrote that "5 and (1)" = 1. That is, that "bit 1" somehow refers to the number 4 (of course, typically bit 1 refers to 1 << 1, e.g. 2, but that's another story).
Anyway, it's human to err, but when someone else points out a potential mistake, and the person in question justifies it with another mistake, then it's obvious that said person has no idea what (s)he is talking about.
Admin
Ever tried to maintain code that is generated by a compiler? The typical trick is to maintain the input, not the output.
Admin
Using #defines for integer constants is a big WTF in modern C/C++, but more importantly, that still produces something remotely readable, e.g. ONE_DAY expands to (24 * (60 * (60 * 1))). A set of macros that expands to "0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1" would have to look something like this:
#define ZERO 0
#define ONE ZERO + 1
#define TWO ONE + 1
#define THREE TWO + 1
...
and then EIGHT would expand to the above string. Strikes me as being a macro WTF, though. Especially since in this case, vital parentheses would be missing - e.g. "SIX * SEVEN" will produce a rather unorthodox result.
Admin
Like they say: "Zero One has tought you well... but you are not a Jed yet!"
Admin
No, a recursive WTF...
Admin
Babylon 5 Episode 21 "Comes the Inquisitor", Season 2.
Admin
And what's wrong with the Peano axioms? Huh? HUH????
All that positional numeral system crap is just syntactic sugar.
Admin
<FONT face="Courier New" size=2>this is a great illustration of why any (human) code that uses bit manipulation can't be trusted. whenever i see code logic based on bits, i destroy it with great magnitude. abstraction is friend.</FONT>
Admin
<FONT face="Courier New" size=2>yeah, if i felt i needed to save face, i would have told you the 'and()' function preformed as stated and had little to do with bitwise 'and'.</FONT>
Admin
I'm not sure that makes it any less of a wtf, though.
Admin
Yes. This is done by editing the parser description. Anything else would be a wtf.
Do you maintain C by editing the generated machine code?
Admin
abstraction, you say?
so who wrote the abstracted methods or functions that you're using? can't have been a human, as their code can't be trusted.
Admin
<FONT face="Courier New" size=2>*sigh*</FONT>
<FONT face="Courier New" size=2>the father, the son, and the holy ghost.</FONT>
Admin
I wonder what's going on here... recursive usage of array...
Admin
Just from the looks of it, I would say that one of the "fields" in these structures contains some kind of relational reference to other structures.