User forums > Using Code::Blocks

How to stop ALL types of file overwriting?

(1/2) > >>

Mountaingod:
Hi, I'm kind of new to programming, more new to C++, and I started using Code::Blocks yesterday (much easier & less cluttered than VS2007).

I turned all the autosaving features I could find off, but still managed to overwrite some code just now at some point. Nothing I'm writing atm is too crucial but I don't like the idea of any .cpp files etc. being written over unless I expressly tell it to.

What I did was:
Saved a bunch of code
Cleared the lot and replaced it with some simpler code I just wanted to test for a second
Compiled & ran that code
Shut down Code::Blocks & restarted to open the 'saved' version of the .cpp file

- but it seems to have saved the small piece of temporary code, over the top of all the stuff that was there before! If I quit CB without saving, it asks me whether I want to (first for the Workspace & then specific files), but this time it didn't.

Am I right in thinking the compiling & running of a file causes it to be silently autosaved first? Can I turn this off?

Thanks.

mrTeoc:
Hello there,

I'm also fairly new to programming myself (I'm not a total newbie, but still...) and started learning C++ a couple of weeks ago :)

As far as I know, you can't do anything simple to disable saving whenever you want to compile your file. The compiler is an external program, and it has to know the location of a .cpp file before it can compile. It's not something that happens in the editor, so the compiler needs to have a saved .cpp file at hand. I suppose automatically saving to a temporary file before a build is a possible solution, but I don't think you can do that and it's not a good approach anyway; it might make sense for single files, but not for projects that use a lot of files which depend on one another.

Whenever you are testing, either save to a temporary file yourself, or comment/uncomment code so that you won't lose anything. Code::blocks has many nice features, such as shortcuts for automatically commenting/uncommenting multiple selected lines of code.

thomas:
If you compile a source, it will be saved, for the reasons pointed out by mrTeoc. There is no way to turn that off, it's expected behaviour. Usually that is not a problem, though.

If you need back revisions of your files, install a revision control system, such as Subversion.

Disabling the autosave plugin will make no difference, since that plugin does not overwrite your files by default (unless you tell it to). Instead it regularly saves your work to a different file.

Mountaingod:
OK, that's what I thought. It's no problem, I'll just have to remember it in the future. I might turn autosaving back on in that case, given it would ironically have saved the stuff I lost!

Thanks

PaulS:
The last Borland C++ IDE that I used managed to compile without overwriting the user's files.  I don't know if they passed working copies to the compiler or saved & then restored the users files.  I liked the idea that my code wasn't changed unless I did an explicit save. 

I can live with either but it is an idea you might consider for the future.

Navigation

[0] Message Index

[#] Next page

Go to full version