Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.objective-c > #206
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Newsgroups | comp.lang.objective-c |
| Subject | Re: Row of objects: for loop creates only 2 rows out of 5 |
| Date | 2015-11-14 22:47 +0100 |
| Organization | Informatimago |
| Message-ID | <87pozc1cfd.fsf@kuiper.lan.informatimago.com> (permalink) |
| References | <fb748a8e-9beb-4d63-866c-11dc8dc55b18@googlegroups.com> |
modelling.data@gmail.com writes:
> Hello!
>
> I have written a post regarding the same program.
>
> I have an issue with the easiest part of it, and I don't see
> my mistake: the for loop in the BRICKS FUNCTION doesn't create
> 5 rows of bricks, but only 2, albeit the amount of columns is correct
> (all bricks are perfectly aligned within 10 columns). The program
> prints out only 2 rows of bricks.
By the way, you will have noticed in my makefile the debug-bricks target
which runs your program with the environment variable JBETRACE set to
true. This allows you to see the traffic sent and received on the pipe
by your program (but you don't see what happens on the other side of the
pipe, data written in the pipe buffer is not necessarily read by the
other side). Nonetheless, this let you see what happens with the GUI
when you have doubts about what you program does.
You should be able to set it on and off using putenv(3):
putenv("JBETRACE=true");
putenv("JBETRACE=false");
if you want to trace only parts of your program.
Secondly, one big problem of batch programming environment such as the
usual C compilers, is that you don't see what's in your variables during
execution or debugging. Granted, you could run a debugger, but gdb or
ldb are low level debuggers, and while you may be able to see what's in
a variable or a data structure, it's rather difficult, and there are all
kinds of exception (notably when optimization levels are higher than 0
(notice the -g -O0 options I use to compile). Therefore, a very common
and useful technique while debugging, is to add to your program a lot of
logs displaying the values of your variables.
Adding a single line such as:
/** BRICKS FUNCTION **/
void initBricks(GWindow window)
{
double x = 10;
double y = VS * 5;
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
/*PJB-DEBUG*/printf("i=%i j=%i x=%f y=%f w=%f h=%f\n",i,j,x, y, BRWIDTH, BRHEIGHT);
GRect brick = newGRect(x, y, BRWIDTH, BRHEIGHT);
add(window, brick);
x = x + BRWIDTH + HS;
}
x = 10;
y = BRHEIGHT + VS;
}
}
would allow you to easily see what one problem was. Notice the
/*PJB-DEBUG*/ comment. You can easily search and replace them to
//PJB-DEBUG to disable such lines, and use:
sed -i -e /PJB-DEBUG/d bricks.c
to remove them entirely once your program works.
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
Back to comp.lang.objective-c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Row of objects: for loop creates only 2 rows out of 5 modelling.data@gmail.com - 2015-11-14 09:14 -0800
Re: Row of objects: for loop creates only 2 rows out of 5 "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-14 22:24 +0100
Re: Row of objects: for loop creates only 2 rows out of 5 modelling.data@gmail.com - 2015-11-15 00:10 -0800
Re: Row of objects: for loop creates only 2 rows out of 5 "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-15 21:40 +0100
Re: Row of objects: for loop creates only 2 rows out of 5 modelling.data@gmail.com - 2015-11-17 07:30 -0800
Re: Row of objects: for loop creates only 2 rows out of 5 "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-14 22:47 +0100
Re: Row of objects: for loop creates only 2 rows out of 5 modelling.data@gmail.com - 2015-11-15 00:12 -0800
csiph-web