... and that has helped a lot to remember some programming concept.
Trivia: overflowing an integer in C is undefined behaviour (C89 at least, haven't checked C99), but in C++ is defined for unsigned integral types.
Certainly helps remember to assess what size integer you should be using, if you pretend that overflowing it will crash the system instead of wrapping around. Obviously very few compilers/systems ever actually did that for arithmetic overflow in C.
I think Duff's Device qualifies as trivia.
dsend(to, from, count)
char *to, *from;
int count;
{
int n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n > 0);
}
}
The concept that it illustrates is that there's always a better way to obfuscate (or optimize, take your pick) your code.
Along the lines of pointless obfuscation in the name of optimization:
a ^= b; b ^= a; a ^= b;
(Try working it through with a couple binary numbers)
a=0110 (6) b=1010 (10)
a^=b; // a=1100
b^=a; // b=0110
a^=b; // a=1010
The only way I know of to swap two variables without using ANY additional memory.
An important programming concept is to limit and control side effects.
State of the art in doing this right would have to include the language Haskell. State of the art in doing this wrong would have to include this ancient piece of trivia:
The old IBM mainframes had an assembler language instruction called EX for 'execute'. In one low level machine cycle, EX enabled the programmer to copy a piece of addressable memory from anywhere, perform a boolean operation on the bits, and then try to execute those bits. This makes COBOL's worst 'alter goto' instruction seem tame. As if 'goto' wasn't bad enough, 'alter goto' changes the 'goto' based on dynamic state.
Your basic Int16 has a maximum range of 32,767 (positive or negative) for its value.
It got me some street cred with some friends watching Jeopardy once and actually helped us solve a problem due to an Id field or something to that effect was only using the Int16 and the records had far exceeded that.
I found this in real code, it's very elegant:
unsigned char a[256];
a[0] = 0;
for (int i=1; i < 256; i++)
a[i] = (a[i>>1]>>1) | ((i&1)<<7);
Took me quite a while to understand what it does, but after that dynamic programming came easily.
If you solve it put it in the comments :-)
I think the origin of the Oracle DUAL table is pretty trivial, and pretty interesting. See here: http://stackoverflow.com/questions/73751/what-is-the-dual-table-in-oracle and scan to the quote from Chuck Weiss.