[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: pointers and Windows debugging

From: Florin Iucha <florin_at_iucha.net>
Date: 2003-01-07 01:26:19 CET

On Mon, Jan 06, 2003 at 04:19:35PM -0800, rbb@rkbloom.net wrote:
> Asserts are generally a bad thing IMO. If something should be checked in
> debug code, it should also be checked in production code.

Asserts are not for argument checking.

Argument checking is for verifying inputs to your module/function/method.
Asserts are used for internal consistency checking.

   Application
   -----------------
   Module interface (public methods)
   -----------------
   Module implementation (private methods)

You would put argument checks in the interface methods and add asserts in the
implementation methods.
So if you have a class Array with a method getAt(i) you would verify
that
   i < arraySize
but you would assert that
   arraySize <= allocatedArraySize.

> As for pointers
> being passed without checking for NULL, those checks are usually a waste
> of cycles. If the value is incorrect, then you are most likely to catch
> those problems in your debugging. You are more likely to catch those
> problems if your program segfaults than if you rely on a log message that
> you may miss.

And what if it does not segfault but randomly scribbles some buffer
before commiting to database? A wild pointer access will segfault only
if it points to memory the OS knows you should not have. If it points
to allocated memory, you get random coruption.

Cheers,
florin

-- 
"NT is to UNIX what a doughnut is to a particle accelerator."

  • application/pgp-signature attachment: stored
Received on Tue Jan 7 01:27:40 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.