Calculator Community > Calculator C

OS cleaning up things after program is off?

<< < (2/2)

Vogtinator:

--- Quote from: robly18 on September 10, 2015, 08:31:45 am ---Thank you so so so much for your help!


--- Quote from: Vogtinator on September 09, 2015, 03:19:56 pm ---
--- Quote ---It's gonna feel weird having to take actual measures to get out of a crash.
--- End quote ---
Well, if your program crashes, it's not possible to recover and the calc resets.
abort and std::terminate (C++) are caught and it tries to recover from it, but that's not possible sometimes.
--- End quote ---

Maybe crash isn't the proper word.. I meant as in, failure to read a file and I end up aborting for example. On the computer all I have to do is have the program quit, but here I see myself implementing some ad-hoc version of exceptions using gotos.
--- End quote ---
You can just use C++ exceptions, it's cleaner than abort() anyway.


--- Quote ---
--- Quote from: Vogtinator on September 09, 2015, 03:19:56 pm ---
--- Quote ---EDIT: Bonus third (sorry for so many!), is there any way to track allocated memory so that I may be able to find out if my program has a memory leak?
--- End quote ---
There is no valgrind for ndless, but you can try to modify libsyscalls in the Ndless-SDK a bit to print something on each malloc and free and track it manually over the serial port or have an internal counter: https://github.com/ndless-nspire/Ndless/blob/master/ndless-sdk/libsyscalls/stdlib.cpp#L104

--- End quote ---
How would I go about, say, logging things to a file perhaps? I've tried using the C IO functions, but I found myself unable to write things? It created the file and everything, but failed when I tried to write to it.

--- End quote ---
It should work just fine, can you show us your code?

robly18:
(Sorry for taking so long... School just started.)

Okay so, after trying again I guess it worked. Don't know why I thought it did the first few tries. The first few, there must have been no output, and after I added error checking, when I mistakenly assumed fprintf would return 0 on success, I came to the conclusion that it had failed...

Thanks for all your help!

Navigation

[0] Message Index

[*] Previous page

Go to full version