Advertisement

What is the most bizar syntax you have ever written?

Started by December 05, 2000 03:34 PM
19 comments, last by Marsupial Rodentia 23 years, 6 months ago
here is some code i actually found at work (of course, function names changed, to protect the innocent):

  void function1( long* ptrToLong ){    ASSERT( ptrToLong != NULL );    TRACE( "%d", *ptrToLong );}void function2(){    long val = get_long_val();    long* plong = new long(val);    function1( plong );    delete plong;}  


this was in many places in our code base after one of the spring semester co-op students left.
of course, the matching "delete" was left out in about half of them.

i just thought this was strange for c++.


crazy166
some people think i''m crazy, some people know i am
I wrote this a few months ago: it parses source files replacing one set of calls with another, reordering the parameters as best it can acording to some simple rules. The only things missing are the arrays %replace and %shuffle which are tables of repaacement names and numbers of parameters.

    while (<>) {    @foo = split /\W+/;    foreach $word (@foo) {        if ($replace = $replace{$word}) {            if ($numargs = $shuffle{$word}) {                if ($numargs == 2) {                    s/^(.+?)$word\s*\(([^(),]+)\,\s+([^(),]+)\)/$1$replace\($3, $2\)/ or s/$word/\#\#$replace/;                } elsif ($numargs == 3) {                    s/^(.+?)$word\s*\(([^(),]+)\,([^(),]+)\,\s+([^(),]+)\)/$1$replace\($4, $2,$3\)/ or s/$word/\#\#$replace/;                } elsif ($numargs == 4) {                    s/^(.+?)$word\s*\(([^(),]+)\,([^(),]+)\,([^(),]+)\,\s+([^(),]+)\)/$1$replace\($5, $2,$3,$4\)/ or s/$word/\#\#$replace/;                } elsif ($numargs == 5) {                    s/^(.+?)$word\s*\(([^(),]+)\,([^(),]+)\,([^(),]+)\,([^(),]+)\,\s+([^(),]+)\)/$1$replace\($6, $2,$3,$4,$5\)/ or s/$word/\#\#$replace/;                } else {                    s/^(.+?)$word\s*\(([^(),]+)\,\s+([^(),]+)\,\s+([^(),]+)\)/$1$replace\($4, $3, $2\)/ or s/$word/\#\#$replace/;                }            } else {                s/$word/$replace/;            }        }    }    print;}  
John BlackburneProgrammer, The Pitbull Syndicate
Advertisement
About generated code:

At my work we use a LOT of generated code. My boss wrote a nice java program that generates classes for accessing things in our database. You write the SQL statement in a text file, and it turns it into a full java class.

Its very nice because instead of hardcoding your SQL statements all over the place, every statement is saved in one directory and you can just re-generate and recompile to make a change.

---------------
Ratfest.org
     if (((                                 //  This complicated bit of logic	  ((ch[0] >= 48) && (ch[0] <= 57))  //  will only allow ONE decimal       && (                                 //  point and numbers with FIVE	   ((dp == 0) && (pos < 5 + minus))	    //  digits before it and	 ^ ((dp > 0) && (dp + minus + 3 > pos))    //  THREE digits after.		      ))	    ^ ((ch[0] == 46) && (dp == 0)))	    ^ ((ch[0] == 45) && (pos == 0))) 


In my first major C program, I had to parse floating point input of +/-5.3 format, and this one if statement covered the lot.

It looks pretty tame compared to some of the stuff above!

Cheers

Matt



Heres a snippet of code from an old 2D team MPOG I made. Players could control multiple vehicles (only one at a time).

  void DrawHumans(NDX_Screen *S, RECT window){	int i;	int z;		for(i = 0; i < NUM_HUMANS; i++)	{		if (tanks[i].occupied == 0 && jeeps[i].occupied == 0 && 			hovers[i].occupied == 0 && copters[i].occupied == 0 && humans[i].state & ALIVE && 			humans[i].x + 30 > (int)mapfile.xglob && humans[i].x < (int)mapfile.xglob+640			&& humans[i].y+30 > (int)mapfile.yglob && humans[i].y < (int)mapfile.yglob+480)		{			if (humans[i].name == "JohnDoe" || humans[i].name == "Invalid")				CGamePlayerQuery q(i,player.pid,0);						humanspriteframelist.Draw(S->Back,(int)humans[i].x-(int)mapfile.xglob,				(int)humans[i].y-(int)mapfile.yglob,				(int)humans[i].bodyframe*6+humans[i].walkingframe/2);						if (mx >= (int)humans[i].x-(int)mapfile.xglob-20 && mx <= (int)humans[i].x-(int)mapfile.xglob &&				my >= (int)humans[i].y-(int)mapfile.yglob-25 && my <= (int)humans[i].y-(int)mapfile.yglob+5)			{				char info[50];				sprintf(info,"[%s]",humans[i].name);				screen->Back->Text(info,(int)humans[i].x - (strlen(info)/2)-3 - mapfile.xglob, (int)humans[i].y + 16 - (int)mapfile.yglob, RGB(255,255,255),chatfont);								screen->Back->Lock();				for (z = 0;z<humans[i].health;z++)					screen->Back->PutPixel_16((int)humans[i].x-mapfile.xglob+z,(int)humans[i].y-mapfile.yglob+30,screen->PixelFormat->Rgb(0,255,0));				screen->Back->Unlock();			}		}	}	}  


The logic itself is not complicated... I think its my spaghetti code that makes it so darn ugly

-- Brian
Back when I was learning 80186 assembler, I wrote some code that actually copied new opcodes over itself into the code segment.
It kept the executable size down.
Advertisement
I like this one from my code.
It converts a 8888-RGBA color to a specific
pixel format of a texture.

  Col24Bit = *buf;// Convert to cbm formatColForCBM  = ((((Col24Bit>>16) & 0xFF) >> (8-RBits)) << GBits << BBits) & DDPF.dwRBitMask;ColForCBM += ((((Col24Bit>>8) & 0xFF) >> (8-GBits)) << BBits) & DDPF.dwGBitMask;ColForCBM += ((Col24Bit & 0xFF) >> (8-BBits)) & DDPF.dwBBitMask;ColForCBM += 0xFFFFFFFF & DDPF.dwRGBAlphaBitMask;  


Roppi
Moon Byte Studios
http://www.moonbyte.de
This is part of the code I used for my first so called 3d engine some 7 years ago. It calculates a perspective projection (you know that x2d = x3d / z3d; y2d = y3d / z3d thingie) Hey, I''ve figured out all these formulas by myself


  repeat    k:=k+1;{-------------------X---------------}    delta:=ungle(a,b,points3[k,1],points3[k,2]);    alfa1:=un(alfa-180);    if  (delta>alfa) and (deltaalfa1) then v:=1                                                                          else v:=-1;    if alfa>=180 then v:=v*(-1);    gama:=un(alfa-delta);    if gama>180 then  gama:=gama-180;    if cos(gama*rad)=0 then points2[k,1]:=mx                       else points2[k,1]:=mx+v*abs(sin(gama*rad)/cos(gama*rad))*n;{-------------------Y---------------}    if (sqrt((a-points3[k,1])*(a-points3[k,1])+(b-points3[k,2])*(b-points3[k,2])))=0 then gama:=90      else gama:=arctan(abs(points3[k,3]-c)/(sqrt((a-points3[k,1])*(a-points3[k,1])                      +(b-points3[k,2])*(b-points3[k,2]))));    points2[k,2]:=my-35/48*sign(points3[k,3]-c)*sin(gama)/cos(gama)*n;{---------------dist----------------}    points2[k,3]:=sqrt(sqr(c-points3[k,3])+sqr(a-points3[k,1])+sqr(b-points3[k,2]));{-----------------------------------}  until k=m; 
MonKey JumpArOunD(void (*) (Banana&, HaiRryAss*), Fleas&, Rabies&)

Thats my monkey jumparound function which takes a function pointer as an argument, and other MOnkey attributes
I have a program (s) I wrote so I could use an old computer soley to play mp3s. At one point I had a VB program start when the comp was turned on. It activated a c++ program that sent messages to winamp via SendMessage() and a QBasic program that was activated by the c++ program as a screen saver the looked like the matrix because QBasic is so easy and I had the scrolling chinese letters in 30 mins. The VB program turned off the computer when I pushed ''q'' twice. I don''t know how odd this is, I just thought it was cool having 3 programs made from 3 different languages all working together performaing a single task.

Tazzel3d ~ Zach

I don''t know how all you guys write all those nice quotes, but I havn''t come up with one yet!

This topic is closed to new replies.

Advertisement