Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

I was bored

Name: Ikari Yui 2005-01-14 17:29

...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).

Have fun.

#include <iostream>
using namespace std;
typedef __int64 pszint; /* FOR 64-BIT POINTERS */
typedef unsigned __int64 uint64;
typedef const char* charptr;

template<typename T> inline void For( T val, const T& end, T (*inc)( const T& ), void (*proc)( const T& ) ) { if( val < end ) { proc( val ); For( inc( val ), end, inc, proc ); } }
template<typename T> inline T If( bool cond, T (*proc)(), T (*eproc)() ) { return ( cond ? proc() : eproc() ); }
template<typename T, typename Q> inline Q Comp( T (*one)(), Q (*two)( const T& ) ) { return two( one() ); }
//template<typename T> inline pszint TypeId() { static T tag; return (pszint) &tag; }

void NullProc() {}
int IncrementInt( const int& i ) { return i + 1; }
uint64 GetValue() { return 36762444129608; /* BIG-ENDIAN */ }
charptr ToString( const uint64& str ) { static uint64 temp; temp = str; return (charptr) &temp; }
charptr GetString() { return Comp<uint64, charptr>( GetValue, ToString ); }
void PrintAndPause( const charptr& str ) { cout << str; getchar(); }
void InnerProc() { Comp<charptr, void>( GetString, PrintAndPause ); }
void Body( const int &i ) { If<void>( i <= 5, InnerProc, NullProc ); }
int main() { For<int>( 1, 10, IncrementInt, Body ); }

Name: Anonymous 2005-01-14 19:08

God-awful template metaprogramming for a memory access violation?

for i in [1,10]:
    if (i<=5):
        Print(DereferenceMemoryAt(InvalidLocation)) // segfault here?
        WaitForKeypress()

Name: Anonymous 2005-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 Yui 2005-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: Anonymous 2005-01-15 13:53

__int64 more like long long

Name: Anonymous 2005-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: Anonymous 2005-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 Yui 2005-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.

That make any sense?

Name: Anonymous 2005-01-15 17:59

>>8

Ah.. that's pretty clever.  Though decrypting the whole thing was pretty straightforward considering the for, if, composite functions were self-describing.

Name: Christy McJesus !DcbLlAZi7U 2005-02-23 10:47

Needs more intercal.

Name: Anonymous 2007-06-21 21:11 ID:mtduBmiC

WELCOME TO THE PAST BITCHES. FUCKING BUMP.

Name: Anonymous 2007-06-21 21:12 ID:mtduBmiC

WELCOME TO THE PAST BITCHES. FUCKING BUMP.

Name: Anonymous 2007-06-22 0:05 ID:Heaven

GOODBYE TO THE PAST BITCHES. FUCKING SAGE.

Name: Anonymous 2008-04-09 22:34

That's a nasty little slice of code, doesn't /prog/ think?

Name: Anonymous 2008-04-09 22:54

Needs more SICP

ed2k://|file|Mit%20Press%20-%20Structure%20And%20Interpretation%20Of%20Classical%20Mechanics(1).pdf|10934837|720CD66AE234FE38EE764A157B253889|/

Name: Anonymous 2008-04-10 2:55

>>15
that is sicm, you dolt

Name: Anonymous 2009-03-06 13:25


Type declaration implying DOCTYPE.

Name: Anonymous 2010-09-14 22:08


64 bytes.

# 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

strings are printed "raw" on exit

Name: Anonymous 2010-09-14 22:09


{.'
'?){}{'[o][u]'3/1):1 2%=.@\(;'[/'\+}if}%'[b][i]'\'[/i][/b]'


64 bytes.

# 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

strings are printed "raw" on exit

Name: Anonymous 2010-11-28 5:48

Name: Necromancer 2011-01-16 19:58

necrosis distending the equilibrium

Name: Anonymous 2011-01-17 3:55

<--- check my dubs!!!

Name: Anonymous 2011-02-03 8:21

Name: Anonymous 2013-05-22 17:35

WHOOPS!

Name: Anonymous 2013-06-02 19:33

check em

Name: Anonymous 2013-06-04 7:56

Has been done to death.  Yes, templates are touring-complete.

Name: Anonymous 2013-06-04 7:57

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)

Name: Anonymous 2014-03-24 14:29

what's up?

Name: Anonymous 2014-03-24 22:03

>>13
>le pedophile sage

Don't change these.
Name: Email:
Entire Thread Thread List