haha; It sounds crazy, but the way I was taught to code years ago is that if it can be more explicit it should be. When a function takes an std::string for example, I'll pass in:
Code: Select all
const char* str = "example";
func( std::string( str ) );
Reasoning: I've had more then one job where the compiler we were given was pathetic and didn't do anything for you. I did a bunch of work with windriver vxworks a few years back, and that compiler did not do jack if you didn't baby it through everything. Example:
One of the guys I worked with made the mistake of invoking the function like this:
Now while that does usually pop up a warning, with most modern compilers that implies allocating an integer on the stack and then passing the reference. Not with this one. It just gave 4 bytes at memory location 5. Terrible. This compiler wouldn't even pop an error if you forgot to implement functions etc. It was a nightmare to work with, so ever since then I don't leave little things up to the compiler. Call me paranoid, but I don't trust it and I think that it's always better to not leave too many things implied. There's my story.
'Cool story bro'