A brief intro to smart pointers, covering both auto_ptr
and the Boost smart pointers.
Every C++ programmer should know what these are. If you don’t, you owe it to yourself to spend some quality time with some good C++ books.
A brief intro to smart pointers, covering both auto_ptr
and the Boost smart pointers.
Every C++ programmer should know what these are. If you don’t, you owe it to yourself to spend some quality time with some good C++ books.
The first function simply toggles the characters at the point between “.” and “->”. Not terribly useful.
The second function is a little more interesting. You can put the point by a struct-type variable which is or isn’t a pointer and this function will toggle both the “*” and all of the “.”s and “->”s in the function.
The other day at work we ran into a nasty little bug that was quite tricky and chewed up quite a few hours of a few people’s time. So I thought that as a service to you, my loyal reader, I would post about it and warn you of this tricky little issue that deals with how gcc (or at least some versions of it, including the ancient version that we happen to be using) treats empty structs differently, depending on whether you’re compiling as C or C++…
An interesting and amusing essay on singletons (and C++ and design patterns) that was pointed out to me by Bruce:
I’m working with some C code that is quite well-written but makes a lot of use of some fairly complicated #define
macros. Macros are discouraged by the coding guidelines, but they are a necessary evil here. They could’ve been functions except for the fact that they allocate memory on the stack using alloca
and a function would destroy the memory when it exited. Writing these functions as #define
macros keeps everything in the caller’s stack frame so the allocated memory remains valid.
The only problem is that #define
macros are a pain in the butt to write and debug. You have to backslash every line (which looks like a mess) and if you forget you get weird errors. You also have to be careful about putting things in scopes and/or giving them funky names to avoid namespace issues. When you do something wrong, you get really weird errors that point you at the calling code instead of the macro itself (because #define
macros essentially are a string replacement).
Too bad we’re not using C++. C++ smart pointers would obviate the need for alloca
, which in turn would obviate the need for the macros.
Here’s what I did (based on a combination of info at http://h8300-hms.sourceforge.net/ and The legOS HOWTO installation page) to build GNU binutils, gcc, and brickOS and associated tools on Mac OS X Tiger 10.4.3 with Xcode 2.2:
Having built a simple Mindstorms robot, but not having the ability to program it, I bought a Lego Mindstorms USB IR tower on eBay.
I can’t wait for it to arrive so I can start messing around with RCX Code, NQC, brickOS (formerly known as “legOS”), Pylnp, etc.