Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TeeJay (2309)

  (email not shown publicly)

Working in Truro
Graduate with BSc (Hons) in Computer Systems and Networks
pm :,,
lug : Devon & Cornwall LUG
irc : TeeJay
skype : hashbangperl
livejournal : hashbangperl []
flickr :hashbangperl []

Journal of TeeJay (2309)

Friday June 11, 2004
03:18 AM

more fun with c++ and hilberts curve

[ #19192 ]
I just spent 45 minutes in gdb trying to figure out why my C++ program was repeatedly segfaulting, after adding breakpoints, stepping through, and adding lots of cout statements printing all the values I finally discovered that where I expected calls to the getCoordinateFromPoint(int point) method I was geting $BIG_NEGATIVE_NUM rather than 1 to 4.

Suspicious - looks like an unitiated value, having use'd strict in perl since the second week, I thought for a moment and looked at the code.. oh dear.. while refactoring I had removed the code using point, but not its declaration, so while I looped through 1 to 4 using point rather than i, the poor code was being asked to look at element $BIG_NEGATIVE_NUM deep inside a dynamic array.

Even using strict wouldn't have caught that, in C and C++ I must remember to initialise all values to 0 when declaring them unless I want to pass around random junk when I use the wrong variable, easier to trace that than segfaults.

Anyway, just before getting off the train I managed to run a test program using the class and killed my machine twice in a row because the code went into a fast infinate loop. I managed to fix that but there are still subtle bugs in the code so that it doesn't quite work for squares larger than 2 x 2. The new code can be found here.

Hopefully on my next train journey I can fix that and add some output via GD.

I would be very grateful if anybody can point me at the equivilent of Test::Simple or Test::More for C++.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • No, not Larry. Always use the -Wall (or -Wall -W) switches, assuming gcc/g++. Of course, maybe you were and it didn't help in this case (?).
    • nope - wasn't using -Wall

      I will start, I guess it sets warning level to all, this is probably helpful when debugging :)


      @JAPH = qw(Hacker Perl Another Just);
      print reverse @JAPH;