Re: [cc65] calloc() not failing

From: Marc 'BlackJack' Rintsch <marc1rintsch.de>
Date: 2012-11-13 13:21:39
On Tuesday 13 November 2012 11:31:58 Oliver Schmidt wrote:
> 
> >> Initialized data is no longer initialized correctly if
> >> the program runs the second time. [...]
> > 
> > ?! This sounds like a bug, even if the solution involves wasting the same
> > amount of memory as the initialized data section. And even more memory is
> > wasted when someone tries to work this around by initializing variables
> > explicitly by code.
> 
> Then all C compilers (at least the ones known to me) have this bug ;-)
> I've never heard of a C compiler keeping an "internal shadow copy" of
> everything changed by a program. That's what the secondary storage is
> for.
> 
> And by the way I find it very interesting that such a big
> misunderstanding can live so long: In example that whole R/O segments
> vs. R/W segments thingy incl. the ld65 options to specify different
> load and run addresses exists only because it's absolutely natural to
> write to non-BSS segments - thus obviously loosing the original
> values!

That was of course known to me.  And I did not expect the program to rerun 
from exactly the same state as after loading.  I just assumed, and experience 
told me, it won't crash on standard library calls.  So if I make sure in my 
code to clean up, e.g. free all memory I allocated, I expected to be able to 
restart the program and that the standard library is able to cope with that.

Or to put it another way: I thought re-running is like putting an endless loop 
around the main functions body minus the destructors and startup code + 
constructers running and that those are „sane”.

> > otherwise people are shooting themselves in the foot right now.
> 
> Therefore I agree with you that it might be worth to invest (a
> considerable small amount of) resources to explicitly "invalidate" the
> program on running it for the first time. Most other targets don't
> have that issue as loading and running is usually a single step there.
> So nobody has the "weird" idea of being able to run a program again.

As the crash on rerun was due to an error in `calloc()` I would disagree with 
invalidating the program.  In general rerunning does work the way I expect 
(and most other users on the C64 I guess).  At least it did for me in the 
past.

Ciao,
		Marc 'BlackJack' Rintsch
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Nov 13 13:28:46 2012

This archive was generated by hypermail 2.1.8 : 2012-11-13 13:28:50 CET