...so I wrote something that I won't understand five bits of in 5 years.
See if you can understand what it does without compiling it. It's valid C++, except for the __int64 type, which is Microsoft-specific (replace with whatever your compiler uses).
God-awful template metaprogramming for a memory access violation?
for i in [1,10]:
if (i<=5):
Print(DereferenceMemoryAt(InvalidLocation)) // segfault here?
WaitForKeypress()
Name:
Anonymous2005-01-14 19:11
Actually, I'm an idiot. I blame it on lack of sleep. Nice work with the 64bit constant to string thing.
Name:
Ikari Yui2005-01-14 20:21
You thought it was a constant pointer (missed the &)?
That'd be fun, you'd need about 34 TB of addressable RAM to run the program even if there was something meaningful there to print (and no memory safeguards in the OS) ...
Name:
Anonymous2005-01-15 13:53
__int64 more like long long
Name:
Anonymous2005-01-15 14:36
My guess is that it just prints out the number in GetValue() as a string five times. I don't know what it says though.
Name:
Anonymous2005-01-15 14:39
Actually, can someone explain what TypeId does? If type T isn't the same size as pszint, wouldn't that cause problems?
Name:
Ikari Yui2005-01-15 15:47
TypeId() declares a static variable of type T, T being the template argument that it was called with (for instance, calling TypeId<int>() will make "tag" have type int). Due to the way templates work, this means that there will be one unique instance of "tag" for each type, allocated on the first call to TypeId with that type. Now, since all instances are unique, they will have unique memory addresses which are not used for anything else = one unique ID for each type. In effect, TypeId enables run-time type identification without RTTI (which creates overhead). I commented it out because my shitty little app doesn't use it.
Ah.. that's pretty clever. Though decrypting the whole thing was pretty straightforward considering the for, if, composite functions were self-describing.
# input pushed at start of code
{ # start function
. # dup
'\s\n' # space, newline
? # find (-1 if not space or nl)
) # increment (now >0, which is true, if space or nl)
### = "if" argument 1: condition
{} # do nothing
### = "if" argument 2: do nothing if space or nl
{ # start block
'[o][u]'# push string
3/ # divide in chunks of three
1 # push 1
) # increment
:1 # store new value in 1, giving the numeral 1 a new meaning
2% # modulo 2
= # n'th element of divided string
.@\ # stack operation dup, rot, swap: [A B] -> [B A B]
(; # drop first
'[/' # push string
\ # swap
+ # join strings
} # end block
### = "if" argument 3: handle bbcode if not space or nl
if # execute if
}% # end and map function over input string
'[b][i]'# push this
\ # swap with input
'[/i][/b]'# push this
# input pushed at start of code
{ # start function
. # dup
'\s\n' # space, newline
? # find (-1 if not space or nl)
) # increment (now >0, which is true, if space or nl)
### = "if" argument 1: condition
{} # do nothing
### = "if" argument 2: do nothing if space or nl
{ # start block
'[o][u]'# push string
3/ # divide in chunks of three
1 # push 1
) # increment
:1 # store new value in 1, giving the numeral 1 a new meaning
2% # modulo 2
= # n'th element of divided string
.@\ # stack operation dup, rot, swap: [A B] -> [B A B]
(; # drop first
'[/' # push string
\ # swap
+ # join strings
} # end block
### = "if" argument 3: handle bbcode if not space or nl
if # execute if
}% # end and map function over input string
'[b][i]'# push this
\ # swap with input
'[/i][/b]'# push this
You can calculate template error messages to produce ascii graphics with T's, <'s and >'s. Maybe even animations (which will be animated by the virtue of scrolling the fuck out of your terminal emulator window)