![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jul 2005
Posts: 158
Rep Power: 0
![]() |
this is a weird output
My pong program uses sdl which sends console IO to a file. I was useing this to debug and I got this It's good for laughs and I have no Idea where it came from. I'm talking about the part at the end I'll post the source and the output. If you can help please if not have a good laugh.
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "SDL\SDL.h"
#include "SDL\SDL_image.h"
#include <iostream>
using namespace std;
class Paddles
{
public:
Paddles()
{
}
int access_x()
{
return x;
}
int access_y()
{
return y;
}
int access_w()
{
return w;
}
int access_h()
{
return h;
}
void move_up()
{
y=y-1;
}
void move_down()
{
y=y+1;
}
void init_x_y(int inix,int iniy)
{
x=inix;
y=iniy;
}
void init_w_h(int iniw,int inih)
{
w=iniw;
h=inih;
}
void ai(int ball_y,int y)
{
if (y<ball_y)
move_down();
if (y>ball_y)
move_up();
}
private:
int x;
int y;
int w;
int h;
};
class ball
{
public:
ball()
{
}
private:
int x;
int y;
int speed;
bool hit_by_p1;
bool hit_by_p2;
bool hit_top;
bool hit_bottom;
bool moving_up;
bool moving_down;
bool moving_backward;
bool moving_forward;
public:
bool did_hit_top()
{
if (y==0)
{
moving_down=true;
return true;
}
else
return false;
}
bool did_hit_bottom()
{
if (y==280-32)
{
moving_up=true;
return true;
}
else
return false;
}
string got_hit(bool event)
{
if (event)
{
if (x<160)
{
moving_forward=true;
moving_backward=false;
if (moving_up)
{
moving_up=false;
moving_down=true;
}
else
{
moving_down=false;
moving_up=true;
}
return "hit_by_p1";
}
if (x>160)
{
moving_backward=true;
moving_forward=false;
if (moving_up)
{
moving_up=false;
moving_down=true;
}
else
{
moving_down=false;
moving_up=true;
}
return "hit_by_p2";
}
}
return "no_hit";
}
void init_x_y(int ix,int iy)
{
x=ix;
y=iy;
}
void move_up()
{
y=y-1;
}
void move_down()
{
y=y+1;
}
void move_forward()
{
x=x+1;
}
void move_backward()
{
x=x-1;
}
void move_upforward()
{
x=x+1;
y=y-1;
}
void move_downforward()
{
x=x+1;
y=y+1;
}
void move_upbackward()
{
x=x-1;
y=y-1;
}
void move_downbackward()
{
x=x-1;
y=y+1;
}
int access_x()
{
return x;
}
int access_y()
{
return y;
}
bool access_hit_top()
{
return hit_top;
}
bool access_hit_bottom()
{
return hit_bottom;
}
bool access_moving_up()
{
return moving_up;
}
bool access_moving_down()
{
return moving_down;
}
bool access_moving_forward()
{
return moving_forward;
}
bool access_moving_backward()
{
return moving_backward;
}
void init_direction()
{
moving_up=true;
moving_forward=true;
}
};
int main (int argc, char *argv[])
{
int score;
int ball_y;
int p2_y;
ball paball;
string loopargs;
string eventargs;
string collisionargs;
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *background;
SDL_Rect screenrect;
SDL_Rect BallRect;
screenrect.x=0;
screenrect.y=0;
screenrect.w=320;
screenrect.h=280;
Uint32 backdrop_color;
Uint8 *keys;
keys=SDL_GetKeyState(NULL);
SDL_Event events;
SDL_Rect rect_conversion(int x,int y,int w,int h);
bool check_collision( SDL_Rect &A, SDL_Rect &B );
string eventarg_creator(bool moveup,bool movedown,bool moveforward,bool movebackward);
Paddles p1;
p1.init_x_y(0,140);
p1.init_w_h(11,43);
SDL_Rect paddle1;
Paddles p2;
SDL_Rect p2rect;
p2.init_x_y(309,140);
p2.init_w_h(11,43);
SDL_Surface *screen=NULL;
SDL_Surface *Paddle1=NULL;
SDL_Surface *Paddle2=NULL;
SDL_Surface *pball=NULL;
Paddle1=IMG_Load("Pong GFX.gif");
Paddle2=IMG_Load("Pong GFX Reverse.gif");
background=IMG_Load("my_size_wii.bmp");
pball=IMG_Load("ball.bmp");
SDL_SetColorKey(pball,SDL_SRCCOLORKEY,backdrop_color);
screen=SDL_SetVideoMode(320,280,32,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/);
backdrop_color=SDL_MapRGB(screen->format,0,0,0);
SDL_SetColorKey(pball,SDL_SRCCOLORKEY,backdrop_color);
paball.init_x_y(160,140);
paball.init_direction();
while (loopargs!="exit")
{
eventargs=eventarg_creator(paball.access_moving_up(),paball.access_moving_down(),paball.access_moving_forward(),paball.access_moving_down());
SDL_FillRect(screen,&screenrect,backdrop_color);
SDL_BlitSurface(background,NULL,screen,NULL);
SDL_PollEvent(&events);
if (events.type==SDL_QUIT)
loopargs="exit";
if (keys[SDLK_ESCAPE]==SDL_PRESSED)
loopargs="exit";
if (keys[SDLK_UP]==SDL_PRESSED)
{
if (p1.access_y()==0)
goto ball;
else
p1.move_up();
}
if (keys[SDLK_DOWN]==SDL_PRESSED)
{
if (p1.access_y()==237)
goto ball;
else
p1.move_down();
}
p2.ai(paball.access_y(),p2.access_y());
ball:
collisionargs=paball.got_hit(check_collision( paddle1, BallRect));
if (collisionargs=="no_hit")
collisionargs=paball.got_hit(check_collision( p2rect, BallRect ));
if (eventargs=="upforward")
paball.move_upforward();
if (eventargs=="downforward")
paball.move_downforward();
if (eventargs=="upbackward")
paball.move_upbackward();
if (eventargs=="downbackward")
paball.move_downbackward();
render:
paddle1=rect_conversion(p1.access_x(),p1.access_y(),p1.access_w(),p1.access_h());
p2rect=rect_conversion(p2.access_x(),p2.access_y(),p2.access_w(),p1.access_h());
BallRect=rect_conversion(paball.access_x(),paball.access_y(),32,32);
SDL_BlitSurface(Paddle1,NULL,screen,&paddle1);
SDL_BlitSurface(Paddle2,NULL,screen,&p2rect);
SDL_BlitSurface(pball,NULL,screen,&BallRect);
SDL_Flip(screen);
if (paball.access_x()<0)
{
p1.init_x_y(0,140);
p2.init_x_y(309,140);
p1.init_w_h(11,43);
p2.init_w_h(11,43);
paball.init_x_y(0,140);
}
if (paball.access_x()>320)
{
p1.init_x_y(0,140);
p2.init_x_y(309,140);
p1.init_w_h(11,43);
p2.init_w_h(11,43);
paball.init_x_y(160,140);
}
SDL_Delay(7);
cout << eventargs << "\n";
cout << paball.access_x() << "\n";
cout << paball.access_y() << "\n";
cout << loopargs << "\n";
}
bail:
SDL_FreeSurface(Paddle1);
SDL_FreeSurface(Paddle2);
SDL_FreeSurface(pball);
SDL_FreeSurface(background);
SDL_Quit();
return 0;
}
SDL_Rect rect_conversion(int x, int y, int w,int h)
{
SDL_Rect temp;
Uint16 newx;
Uint16 newy;
Uint16 neww;
Uint16 newh;
newx=x;
newy=y;
neww=w;
newh=h;
temp.x=newx;
temp.y=newy;
temp.w=neww;
temp.h=newh;
return temp;
}
bool check_collision( SDL_Rect &A, SDL_Rect &B )
{
//The sides of the rectangles
int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;
//Calculate the sides of rect A
leftA = A.x;
rightA = A.x + A.w;
topA = A.y;
bottomA = A.y + A.h;
//Calculate the sides of rect B
leftB = B.x;
rightB = B.x + B.w;
topB = B.y;
bottomB = B.y + B.h;
//If any of the sides from A are outside of B
if( bottomA == topB )
{
return true;
}
if( topA == bottomB )
{
return true;
}
if( rightA == leftB )
{
return true;
}
if( leftA == rightB )
{
return true;
}
//If none of the sides from A are outside B
return false;
}
string eventarg_creator(bool moveup,bool movedown,bool moveforward,bool movebackward)
{
if (moveup&&moveforward)
return "upforward";
if (moveup&&movebackward)
return "upbackward";
if (movedown&&moveforward)
return "downforward";
if (movedown&&movebackward)
return "downbackward";
}upforward
161
139
upforward
162
138
upforward
163
137
upforward
164
136
upforward
165
135
upforward
166
134
upforward
167
133
upforward
168
132
upforward
169
131
upforward
170
130
upforward
171
129
upforward
172
128
upforward
173
127
upforward
174
126
upforward
175
125
upforward
176
124
upforward
177
123
upforward
178
122
upforward
179
121
upforward
180
120
upforward
181
119
upforward
182
118
upforward
183
117
upforward
184
116
upforward
185
115
upforward
186
114
upforward
187
113
upforward
188
112
upforward
189
111
upforward
190
110
upforward
191
109
upforward
192
108
upforward
193
107
downbackward
192
108
downbackward
191
109
no_hit
191
109
no_hit p2 S ] €` _ Ð Y [ x`¤ ÿ A €à C X M à O @ I K €` u Ð w q ÿ ÿ ÿ ÿ €à y X { à e @ g a €` c Ð m o ÐM¤ ÀM¤ °M¤ *M¤ ?M¤ pM¤ €M¤ `M¤ @È @È @ð L¤ ðK¤ L¤ @L¤ PL¤ `L¤ pL¤ N¤ 0N¤ ÀN¤ @ð @N¤ @ èþÿÿ x ÐN¤ ?,
?, € pL¤ `L¤ PL¤ @L¤ L¤ ðK¤ L¤ 8A¤ €O¤ àN¤ ÀN¤ 0N¤ N¤ 1 € 3 M¤ M¤ M¤ ðL¤ àL¤ ÀL¤ ÐL¤ °L¤ ?O¤ 0O¤ ÐN¤ xN¤ N¤ ; €? % €? ' 0M¤ @ @ A¤ ( * ” ˆ¤ Ô 0P¤ PP¤ xP¤ xT¤ >¤ Ñ @ ` p x | ~ €| l F À à ð ø ü þ ÿ ÿ€ÿÀÿàþ ï Ï ‡€€ Ú Û ?ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿ ÿÿ ?ÿÿ ÿÿÿÿÿÿÿÿ0ÿÿÿxÿÿøÿÿüÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ô À * ? ˆ „ ‚ ? €€ €@ ƒà ’ © É „€ € å ßSwçSws!SwQ!Sw£!SwïSw"Sw2SwBSw SwSw – s/òsx¤ ‡ g ð_*Z°Z°]à] _€_Ð h[¤ `Z ¸ ¥ L
ÿÿÿÿ ÷Åw W ´ `¤ Q P¤ B Ȥ s @¤ l ±Cªw¸¤ _ÉvpÉv*Év?Év÷Év“Év }Ãv¨¤ ? ¤ 9 E:\ ¤ ; À °µ À – À ? À °µŽ À °µ? À °µ? À °µ‘ À °µ’ À °µ“ À °µ Ô ÿÿÿÿdownbackward ÿÿÿ Ñ €L¤ + ?d¤ + *f¤ Ú ˆ`¤ ? Ä € € €€ € € € €€ €€€ ÀÀÀ ÿ ÿ ÿÿ ÿ ÿ ÿ ÿÿ ÿÿÿ 3 f ™ Ì ÿ 3 33 3f 3™ 3Ì 3ÿ f f3 ff f™ fÌ fÿ ™ ™3 ™f ™™ ™Ì ™ÿ Ì Ì3 Ìf Ì™ ÌÌ Ìÿ ÿ ÿ3 ÿf ÿ™ ÿÌ ÿÿ 3 3 3 3 f 3 ™ 3 Ì 3 ÿ 33 333 33f 33™ 33Ì 33ÿ 3f 3f3 3ff 3f™ 3fÌ 3fÿ 3™ 3™3 3™f 3™™ 3™Ì 3™ÿ 3Ì 3Ì3 3Ìf 3Ì™ 3ÌÌ 3Ìÿ 3ÿ 3ÿ3 3ÿf 3ÿ™ 3ÿÌ 3ÿÿ f f 3 f f f ™ f Ì f ÿ f3 f33 f3f f3™ f3Ì f3ÿ ff ff3 fff ff™ ffÌ ffÿ f™ f™3 f™f f™™ f™Ì f™ÿ fÌ fÌ3 fÌf fÌ™ fÌÌ fÌÿ fÿ fÿ3 fÿf fÿ™ fÿÌ fÿÿ ™ ™ 3 ™ f ™ ™ ™ Ì ™ ÿ ™3 ™33 ™3f ™3™ ™3Ì ™3ÿ ™f ™f3 ™ff ™f™ ™fÌ ™fÿ ™™ ™™3 ™™f ™™™ ™™Ì ™™ÿ ™Ì ™Ì3 ™Ìf ™Ì™ ™ÌÌ ™Ìÿ ™ÿ ™ÿ3 ™ÿf ™ÿ™ ™ÿÌ ™ÿÿ Ì Ì 3 Ì f Ì ™ Ì Ì Ì ÿ Ì3 Ì33 Ì3f Ì3™ Ì3Ì Ì3ÿ Ìf Ìf3 Ìff Ìf™ ÌfÌ Ìfÿ Ì™ Ì™3 Ì™f Ì™™ Ì™Ì Ì™ÿ ÌÌ ÌÌ3 ÌÌf ÌÌ™ ÌÌÌ ÌÌÿ Ìÿ Ìÿ3 Ìÿf Ìÿ™ ÌÿÌ Ìÿÿ ÿ ÿ 3 ÿ f ÿ ™ ÿ Ì ÿ ÿ ÿ3 ÿ33 ÿ3f ÿ3™ ÿ3Ì ÿ3ÿ ÿf ÿf3 ÿff ÿf™ ÿfÌ ÿfÿ ÿ™ ÿ™3 ÿ™f ÿ™™ ÿ™Ì ÿ™ÿ ÿÌ ÿÌ3 ÿÌf ÿÌ™ ÿÌÌ ÿÌÿ ÿÿ ÿÿ3 ÿÿf ÿÿ™ ÿÿÌ ÿÿÿ B ? E áá66=6=/Sáá á06·6=66/Sá ÜÜøññêêã㸔 ÜãññêêêãããÜ ÜãñññêêãêãÜ ÜãññêêããããÜ ÜÜøññêêãêÜÜ ((((((((((( S~ÿÔÔ©©~(SS S~ÔÔ©©~~(S( S~ÿÔÔ©©~(SS (~ÔÔ©©~(((( S~ÿÔÔ©©(~SS (~©©©~Ü(SS( S~ÿÔÔ©©~~SS (~ÔÔ©©~~SS( S~ÿÔÔ~F~~SS S~ÔÔ©©~(((( S~ÿÔÔ©©~(SS (~ÔÔ©©~~(S( S~ÿÔÔ©©(((( (~©©©~Ü~S(( S~ÿÔÔ©©(((( (~ÔÔ©©~~(S( S~ÿÔÔ©©~(SS S~ÔÔ©©~(((( S~ÿÔÔ~F~~SS (~ÔÔ©©~~SS( S~ÿÔÔ©©~~SS (~©©©~Ü(SS( S~ÿÔÔ©©(~SS (~ÔÔ©©~(((( S~ÿÔÔ©©~(SS S~ÔÔ©©~~(S( S~ÿÔÔ©©~(SS ((((((((((( ÜãñññêêãêãÜ ÜãññêêããããÜ ÜÜñññêêãêÜÜ ÜãññêêêãããÜ ÜãñññêêããÜ” á56·6=66/Sá áá6666=/Sáá B *O¤ 8! `9 Èf¤ ÐR g¤ + hk¤ + xm¤ 7 Pg¤ ÿ = `g¤ ? ? € € €€ € € € €€ €€€ ÀÀÀ ÿ ÿ ÿÿ ÿ ÿ ÿ ÿÿ ÿÿÿ 3 f ™ Ì ÿ 3 33 3f 3™ 3Ì 3ÿ f f3 ff f™ fÌ fÿ ™ ™3 ™f ™™ ™Ì ™ÿ Ì Ì3 Ìf Ì™ ÌÌ Ìÿ ÿ ÿ3 ÿf ÿ™ ÿÌ ÿÿ 3 3 3 3 f 3 ™ 3 Ì 3 ÿ 33 333 33f 33™ 33Ì 33ÿ 3f 3f3 3ff 3f™ 3fÌ 3fÿ 3™ 3™3 3™f 3™™ 3™Ì 3™ÿ 3Ì 3Ì3 3Ìf 3Ì™ 3ÌÌ 3Ìÿ 3ÿ 3ÿ3 3ÿf 3ÿ™ 3ÿÌ 3ÿÿ f f 3 f f f ™ f Ì f ÿ f3 f33 f3f f3™ f3Ì f3ÿ ff ff3 fff ff™ ffÌ ffÿ f™ f™3 f™f f™™ f™Ì f™ÿ fÌ fÌ3 fÌf fÌ™ fÌÌ fÌÿ fÿ fÿ3 fÿf fÿ™ fÿÌ fÿÿ ™ ™ 3 ™ f ™ ™ ™ Ì ™ ÿ ™3 ™33 ™3f ™3™ ™3Ì ™3ÿ ™f ™f3 ™ff ™f™ ™fÌ ™fÿ ™™ ™™3 ™™f ™™™ ™™Ì ™™ÿ ™Ì ™Ì3 ™Ìf ™Ì™ ™ÌÌ ™Ìÿ ™ÿ ™ÿ3 ™ÿf ™ÿ™ ™ÿÌ ™ÿÿ Ì Ì 3 Ì f Ì ™ Ì Ì Ì ÿ Ì3 Ì33 Ì3f Ì3™ Ì3Ì Ì3ÿ Ìf Ìf3 Ìff Ìf™ ÌfÌ Ìfÿ Ì™ Ì™3 Ì™f Ì™™ Ì™Ì Ì™ÿ ÌÌ ÌÌ3 ÌÌf ÌÌ™ ÌÌÌ ÌÌÿ Ìÿ Ìÿ3 Ìÿf Ìÿ™ ÌÿÌ Ìÿÿ ÿ ÿ 3 ÿ f ÿ ™ ÿ Ì ÿ ÿ ÿ3 ÿ33 ÿ3f ÿ3™ ÿ3Ì ÿ3ÿ ÿf ÿf3 ÿff ÿf™ ÿfÌ ÿfÿ ÿ™ ÿ™3 ÿ™f ÿ™™ ÿ™Ì ÿ™ÿ ÿÌ ÿÌ3 ÿÌf ÿÌ™ ÿÌÌ ÿÌÿ ÿÿ ÿÿ3 ÿÿf ÿÿ™ ÿÿÌ ÿÿÿ B ? ¸ ááS/=6=66áá áS/66=6·65á ”ÜããêêñññÜÜ Üããã¿êêññãÜ ÜãêãêêññøãÜ ÜãããêêêññãÜ ÜÜêãêêñññÜÜ ((((((((((( SS(~©©ÔÔÿ~S (S(~©©©ÔÔ~S SS(~©©ÔÔÿ~S ((((~©©ÔÔ~S SS~(©©ÔÔÿ~S (SS(Ü~©©©~( SS~~©©ÔÔÿ~S (SS~~©©ÔÔ~S SS~~F~ÔÔÿ~S ((((~©©ÔÔ~S SS(~©©ÔÔÿ~S (S(~~©©ÔÔ~S ((((©©ÔÔÿ~S ((S~Ü~©©©~( ((((©©ÔÔÿ~S (S(~~©©ÔÔ~S SS(~©©ÔÔÿ~S ((((~©©ÔÔ~S SS~~F~ÔÔÿ~S (SS~~©©ÔÔ~S SS~~©©ÔÔÿ~S (SS(Ü~©©©~( SS~(©©ÔÔÿ~S ((((~©©ÔÔ~S SS(~©©ÔÔÿ~S (S(~©©©ÔÔ~S SS(~©©ÔÔÿ~S ((((((((((( ÜãêãêêññøãÜ ÜãããêêêññãÜ ÜÜêãêêñññÜÜ ¸ããããêêñÍãÜ •ÜããêêññøãÜ áS/66=6“60á ááS/66=66áá B z *O¤ : :mad: :mad:There are even trademark symbols in the original.
__________________
Geeks may not be cool now but in the long run they prosper. |
|
|
|
|
|
#2 |
|
Hobbyist
Join Date: Sep 2005
Posts: 261
Rep Power: 4
![]() |
Are you sure you've posted the right code? cos' the code posted above shouldn't even compile.
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jul 2005
Posts: 158
Rep Power: 0
![]() |
It compiles and it runs why shouldn't it compile.
__________________
Geeks may not be cool now but in the long run they prosper. |
|
|
|
|
|
#4 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
I stopped reading your code at the headers... I swear that <stdio.h> and <stdlib.h> were addressed in another thread. Change them to <cstdio> and <cstdlib>, respectively.
[edit:] I was wrong. I noticed them but forgot to mention it... :o |
|
|
|
|
|
#5 | |
|
Hobbyist
Join Date: Sep 2005
Posts: 261
Rep Power: 4
![]() |
Quote:
class ball { //... }; // <--Note: global scope here.
// ...
if (p1.access_y()==0)
goto ball;
ball: |
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,207
Rep Power: 5
![]() |
I haven't gone through the code in detail, but the obvious guess is that the problem is some variables (or data members of your classes) are uninitialised. In particular, the constructors for classes Paddles and ball do not initialise their data members, which means the values they start with are unpredictable.
A simpler form would be; #include <iostream>
class X
{
public:
X();
int getX() const {return x;};
private:
int x;
}
int main()
{
X x;
std::cout << x.getX() << '\n';
}Formally, reading any uninitialised variable (which you have to do to return it from a function, increment it, or print it) yields undefined behaviour. It just happens that printing junk is one common symptom. |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Jul 2005
Posts: 158
Rep Power: 0
![]() |
I'v gone through a few bug fixes and the ridiculous output is gone. The output was to trace down an error because dev-c++ doesn't have a good debugger in my opinion again I am not at my home computer and I had to settle for what I have. You need to have SDL installed for it to compile and you need to add the libraries SDL.lib(or .a), SDLmain.lib(or .a), and SDL_image.lib(or .a). The bugs I were tracking weren't anything dangerous so you could build that but I wouldn't recommend it as it does some truly rediculous things. Thanks for your input everyone. The funny thing was the variable I printed was initialized but oh well.
__________________
Geeks may not be cool now but in the long run they prosper. |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Jul 2005
Posts: 158
Rep Power: 0
![]() |
I also changed the label I thought I got rid of that already.
Thanks.
__________________
Geeks may not be cool now but in the long run they prosper. |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Getting rid of the 'goto ball' requires only a little bit of additional thinking on your part. Just reconsider the logic somewhat and it'll strengthen your programming.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,207
Rep Power: 5
![]() |
teencoder, you have a different definition of "not dangerous" than I do. Unexplained junk output is usually a symptom of something fairly nasty.
If your variables are initialised, then the most obvious other cause of your original problem is pointer molestation (eg falling off the end of an array, writing to a NULL, etc) that is overwriting your variables. It strikes me that your approach to debugging is simply tweaking code until the symptoms of problem (seem to) go away. Given that you can't explain *why* your changes seem to have fixed the problem, I wouldn't have a lot of faith in your claim that the real problem is fixed. And I agree with Dawei: your use of goto in this case is easy to get rid of in a clean manner. I'd also suggest some effort into cleaning up your code so you can actually understand it. Unless you enjoy coming back to code a few months after you wrote it, thinking "what idiot wrote this?", and then realising ..... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|