Game Development Community

What am I doing wrong (for fun)

by Michael Perry · in Technical Issues · 07/17/2007 (11:25 am) · 8 replies

Writing a new game engine, and I'm testing out some coding concepts I've never heard of. Thought I'd try them in a simple main loop first...something is going really wrong...

#include <iostream>
using namespace std;

void main()
{
	goto start;

start:
	for(int i = 0; i < 9999; i++)
        char* x = new char[9999];

	goto middle;

middle:
	int* YyysIIlkk;
	int bob = *YyysIIlkk +3;

	goto end;

end:
	// End of application =)
}

Suggestions?

#1
07/17/2007 (11:47 am)
Well first of all you're not deallocating/deleting the 10,000 char pointers which youre creating and allocating 9999 bytes each for, secondly you're setting bob to three plus the integer which YyyxIIlkk points to which was never given a value.
#2
07/17/2007 (11:49 am)
Thirdly, you're using goto, which is evil.
#3
07/17/2007 (11:50 am)
I'm gonna go with YyysIIlkk is pointing to nothing and will crash when its bob is assigned to it plus 3.

Doh, beat to it and I missed the deleting.
#4
07/17/2007 (11:57 am)
Hmmm, well the compiler should catch the 'YyysIIlkk' not being initialized. If it has garbage memory assigned to it, though, than dereferencing it should cause an access violation. If it doesn't, than the value of bob is undefined (well I guess undefined +3).

I'm kind of confused about what coding concepts this is demonstrating. Massive allocation of unreferenced memory, random goto's, and dereferencing of unassigned pointers. This must be an entry for a coding competition I am not aware of.
/*
 * Program to compute an approximation of pi
 * by Brian Westley, 1988
 * (requires pcc macro concatenation; try gcc -traditional-cpp)
 */

#define _ -F<00||--F-OO--;
int F=00,OO=00;
main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
{
            _-_-_-_
       _-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
        _-_-_-_-_-_-_-_
            _-_-_-_
}
There, try that one...
#5
07/17/2007 (12:03 pm)
Why would you need to compute an approximation of pi?

Pi == 3; // Exactly equal to

Right?

*Edit*- On a side note...that is an awesome chunk of code Pat =)
#6
07/17/2007 (1:27 pm)
Well that program just doesnt make any sense whatsoever. =)
#7
07/17/2007 (1:47 pm)
Lol, those goto's are funny.

I like how they do nothing and mean less.
a Real instantiation of fugly code.
#8
07/17/2007 (1:52 pm)
Nice :) Want some more? Visit www.ocf.berkeley.edu/~wwu/1337/code.shtml