Saturday, 19 March 2011

Me and My Compiler . . .


Research tends to portion tasks in phases. Sometimes, the week's tasks will involve making many, many, many slides. Sometimes one may find one's self reading papers until one's brain hurts. And sometime, the need arises for new code. Perhaps the old code isn't adequate for how the project has evolved. Perhaps you went on vacation for a week and cannot remember what in the world your code was doing any more. Perhaps you started a new project, and thought to yourself, hey, I can use all the clever ideas I've been collecting to improve my analysis!

Whatever the reason, you settle down for some quality time with your compiler. If, like me, you don't code every single day and tend to forget the nuances, allow me to share a few hints my compiler taught me.

My compiler does not throw an error when someone forgets to put the return statement in the function. It throws a warning, but otherwise compiles everything just fine. This is a bit of a problem if that function returns a pointer you actually want to use (unless of course causing a seg-fault is what you wanted to do . . .). So don't forget the return statement.

Templated functions can save you a lot of coding on repetitive tasks. But templated functions should not be included with the rest of your source code. They need to be in the header file or in a special file of their own. Your compiler will compile the functions with the source code just fine, and then have no idea what function you're trying to call when you actually run your code. Since ROOT errors messages are about as useful as an elephant in ballet class, figuring out why your function has gone missing can take some puzzling, particularly if you've been at your desk for more than ten hours.

No comments: