User Name
Password
AppleNova Forums » Programmer's Nook »

Templates :: Step through fine in Debug, but crash when run in anger...?


Register Members List Calendar Search FAQ Posting Guidelines
Templates :: Step through fine in Debug, but crash when run in anger...?
Thread Tools
scratt
Veteran Member
 
Join Date: Jul 2004
Location: M-F: Thailand Weekends : F1 2010 - Various Tracks!
Send a message via Skype™ to scratt 
2005-12-17, 07:24

Hi there..

I am experimenting with some template stuff in Xcode..

I have a strange problem...

When I step through them using Debug everything is fine.. The IO log window outputs what I expect, and the trace of the code is faultless.. Variables and pointers all behave impeccably..

However, when I run it 'for real' in Xcode I get exceptions...

Anyone know of any quirks with templates and Xcode?

It's pretty basic stuff. Nothing fancy.

I have tried all the dumb stuff.. Cleaning, reloading everything etc. etc.

'Remember, measure life by the moments that take your breath away, not by how many breaths you take'
Extreme Sports Cafe | ESC's blog | scratt's blog | @thescratt
  quote
Kickaha
Veteran Member
 
Join Date: May 2004
 
2005-12-17, 09:51

Er, do you mean project templates, or C++ templates?
  quote
scratt
Veteran Member
 
Join Date: Jul 2004
Location: M-F: Thailand Weekends : F1 2010 - Various Tracks!
Send a message via Skype™ to scratt 
2005-12-17, 10:04

Quote:
Originally Posted by Dr. Kickaha
Er, do you mean project templates, or C++ templates?
Hey buddy....

Actually I solved it about 10 minutes ago..

I was talking about C++ templates.
It was very wierd.. One of those 1 in a million bugs.. A pointer in a routine about half a page up was overwriting the end of some string space and randomly affecting the code, causing crashes... But it only manifested itself after I had included a whole load of templates for repetative search functions..

I must be using so many levels of indirection that the compiler didn't pick up the fact that I was writing wildy outside the boundaries of my data... Strange...

But that'll teach me to try and be clever...

'Remember, measure life by the moments that take your breath away, not by how many breaths you take'
Extreme Sports Cafe | ESC's blog | scratt's blog | @thescratt
  quote
Kickaha
Veteran Member
 
Join Date: May 2004
 
2005-12-17, 10:27

The compiler won't.

C++ doesn't have any concept of writing past the end of an array, you're welcome to do it. Heck, it doesn't have the concept of writing before the beginning of the array either. Had a boss do the following once as a down and dirty 'struct' for a three dimensional array:

const int LEN = X * Y * Z;
int a[LEN + 3];
a = a +3;

a[0]...a[LEN] acted as expected.
a[-3]...a[-1] were storage for the lengths of the each axis. So you always had the proper sizes being carried around with it. In theory.

Personally, I thought he was bonkers, but it worked pretty well... until the day a student misread the documentation... oy.

The point is, you can have an array that's N long, and access [N*10] if you want, or [-N]. C/C++ won't care, and won't stop you.

Glad you got it figured out.
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does software crash, freeze and hang? dahacouk General Discussion 32 2005-11-15 14:48


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 21:20.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova