Safety in C++
Ok, so here's another newbie question. So in VB.Net the whole thing was about managed code. So now in the transition to C++ I fond myself in a 'Un-Managed' world. Therefore the question is that in VB.Net any call made to Native Win32 Methods would result in the common language runtime making sure that 'Nothing Could Go Wrong' So how do we effect this in C++, or am i just being a dipstick and not thinking about this hard enough. :confused:
The reason i ask is beacuse i've been playing around with different functions and nothing has 'gone wrong' yet.
[599 byte] By [
zeek840] at [2007-11-11 10:23:29]

# 1 Re: Safety in C++
C++ isn't VB, so you have think in a different way. In standard C++ at least, there are usually not as many guarantee as in VB with respect to operating system's guarding services. You simply have to know the rules, use efficient and secure programming techniques and test your code. The benefit of removing all the Managed code guarads are, IMO, worth their while: your code is faster, more portable and gives you more control over the execution environment. So you won't find automatic garabage collection or automatic and safe conversions of strings to integers. Instead, you need to learn how to use the Standard Library's rich set of classes and algorithms to get what you want. I know it's a very general answer but it should give you a taste of the philosophy behind C++'s design: pay as you go, and trust the programmer.
Danny at 2007-11-11 20:59:00 >

# 2 Re: Safety in C++
Implement exception handling mechanism.
# 3 Re: Safety in C++
you can use managed c++, but its very limiting.
You can get safe librarys too, if you are afraid of yourself and working on production code. For example, boost.org has garbage collecting pointer wrappers, etc. These have overhead and basically bloat your code in exchange for protections against novice mistakes. They are good librarys for what they do.
I make it a habit of avoiding dynamic memory most of the time, its slow and creates most of these issues. Most of the time, on modern computers with huge stacks and address space, its not really necessary.
jonnin at 2007-11-11 21:00:59 >

# 4 Re: Safety in C++
you can use managed c++, but its very limiting.
You can get safe librarys too, if you are afraid of yourself and working on production code. For example, boost.org has garbage collecting pointer wrappers, etc. These have overhead and basically bloat your code in exchange for protections against novice mistakes. They are good librarys for what they do.
Think i'll probably stick to learnind the hard way, but it's good to know that there are libraries out there if I get tired of trying. :)
I make it a habit of avoiding dynamic memory most of the time, its slow and creates most of these issues. Most of the time, on modern computers with huge stacks and address space, its not really necessary.
So with thatsaid and what little i know about array's in C++, are you saying that you would always prefer to stick to fixed size array?
Thanks again for the replies. I'll admit i happened upon these forums by chance and i'm glad i did. It's nice to know there is somewherew to go to ask the most ridiculous of questions and not get set-upon for being an idiot.
Thanks again,
Regards Zeek
# 5 Re: Safety in C++
the STL (standard template lib) has this nifty thing called vectors. If a fixed size array wont do ya, this will grow to fit and is self-managing. Its got some overhead against a straight array, but its loaded with cool featuers too. If you need its power, use it, if not, use an array, there are times where both have a place.
There is a time for dynamic memory and certainly, you can take the address of things and do some cool pointer code without the dynamic issues. There are times when either of these tools are useful as well. Of course you can blow the bounds on a pure array too, so not using it is not foolproof. Just avoid the temptation to stick pointers everywhere, its a bad habit that is self reinforcing because so much "viewable" code (public domain) is full of "pointers for the sake of pointers" or "pointers to get around design flaws".
jonnin at 2007-11-11 21:03:04 >
