On Tue, 27 Nov 2001, Chris Tutty wrote:
> MemHandle BlahGetNextItem(UInt16 * Index)
> {
>  if (mBlahDB == NULL)
>   return NULL;
>
>  return DmQueryNextInCategory(mBlahDB, Index, mCategory);
> }

  MemHandle BlahGetNextItem(UInt16 *Index)
  {
    MemHandle result = NULL;
//  ErrFatalDisplayIf(mBlahDB == NULL, "bullocks, database is not open");
    if (mBlahDB) result = DmQueryNextInCategory(mBlahDB, Index, mCategory);
    return result;
  }

  try rewriting it.. :) also, if that doesn't work.. uncomment the
  ErrFatalDisplayIf call :)

> which is set using an OpenBlahDB function called when the module
> is first accessed.

  100% sure about this?

> This function is always returning NULL.  In fact, the debugger only
> shows the '-' (showing an 'active' source line) beside the opening
> and closing braces and the 'return NULL' line.  The only thing I
> can think of is that the compiler thinks that the test will always
> return true and is dead-stripping the rest of the function.  The 'if'
> statement is never being executed.
>
> On the other hand the assembler seems to include it (my 15-year
> old memory of assembler suggests that a 'tst.l' followed by a 'bne'
> is a Branch on Not Equal and so would seem to be reasonable
> assembler for an if test against NULL) but the debugger clearly
> shows that variable as non-NULL and yet the test is being acted
> on as if true.

  15-year old? hehe.. he's just perfect for the warez group! :)
  [for all you know, maybe he is] :P

> This code is in a static library and is compiled with optimisation
> level set to 1.  Having noticed this I've set the optimisation level
> to 0 (no deadstripping, among other things) and it seems to have
> fixed the problem (surprising how many things you find while
> carefully explaining the problem to someone else) but I don't see
> how this is valid behaviour for the optimiser.
>
> I've run into this kind of dead-stripping problem before with v6
> and fixed it by forcing a side-effect in the block being dead-stripped
> but seeing the same sort of problem in v7 worries me.
>
> So.  Is it something stupid I'm doing or the compiler?

  i think its probably the compiler, trying to be too smart.. :)
  having multiple returns in a function can confuse the compiler
  (not to mention it is bad programming) :P

  just try rewriting the function a bit..

// az
[EMAIL PROTECTED]
http://www.ardiri.com/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to