View Single Post
  #8 (permalink)  
Old 06-09-2010, 07:53 PM
Keith Thompson
Guest
 
Posts: n/a
Default Re: increment and loop error

barry <nospam@nospam.com> writes:
> Keith Thompson wrote:

[...]
>> Among other things, you haven't shown us the declarations of any of the
>> 8 variables you refer to, or the code you use to display the value of
>> ii.
>>
>> In reducing your code to a minimal example, you appear to have removed
>> whatever caused the problem you're observing. Post a small, complete,
>> compilable, executable program that clearly exhibits the problem, and we
>> can probably help you. (It's also fairly likely that you'll solve the
>> problem yourself while creating such a test case.) Copy-and-paste the
>> exact program source and its output; don't just summarize or describe
>> either.

>
> The actual .c file is over 8000 lines long and I didn't think it was
> appropriate to post it all.


You're right, that would be too long.

> The function IS this:
>
> static int TwoDToOneD(void) {
>
> int i,j, ii;
>
> MALLOC(ret.lightcon, sizeof(float*)*AreaRow/res*AreaCol/res);

[7 lines deleted]
>
> ii = 0;
> printf("Row: %d\tCol: %d\n", AreaRow/res, AreaCol/res);
> for (i = 0; i < AreaRow/res; i++) {
> for (j = 0; j < AreaCol/res; j++) {
> printf("ii: %d\ti: %d\tj: %d\n", ii, i, j);
> ret.lightcon[ii] = work.lightcon2D[i][j];

[7 lines deleted]
> ii++;
> }
> }
> for (i = 0; i < AreaCol; i++) {
> free(work.lightcon2D[i]);

[7 lines deleted]
> }
> free(work.lightcon2D);

[7 lines deleted]
>
> return 1;
> }


That's still not very helpful.

You need to do some work here. If you can pare down your code to
something *small* and *self-contained* that clearly exhibits the
problem, we can probably help. The code you posted still refers to
a blortload of variables whose declarations you haven't shown us.
We don't know how MALLOC (presumably a macro) is defined. I haven't
studied the code in depth, but it's still likely that you haven't
shown us the code that's actually causing the problem.

You're processing 8 different sets of arrays; pare that down to 1.
Don't worry about the pared-down program being functionally useful;
just do something that clearly misbehaves in the same way as your
original program. And so forth.

Also, please don't top-post (I've corrected it here). See:

http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Reply With Quote