Posts Tagged ‘pointers’

The Great Pointer Conspiracy

Thursday, July 30th, 2009

One of the great tragedies of C and C++ is that they are taught wrong — that a num­ber of per­fectly straight­for­ward fea­tures are taught and described as if they were myth­i­cal and super­nat­ural enti­ties that no mor­tal can truly under­stand. Mem­ory man­age­ment in C++ is one such fea­ture (it is actu­ally very sim­ple, once you know the trick), but the biggest of all is prob­a­bly pointers.

Every­one who learns C++ fears point­ers. Every­one who is new to the lan­guage, or who has merely heard of the lan­guage con­sider point­ers to be some kind of magic — arcane con­structs that give the pro­gram­mer access to Real Ulti­mate Power — a fea­ture that both mark C/C++ as supe­rior and more pow­er­ful than other lan­guages, but is also feared as dan­ger­ous or unsafe*.

None of this is true.

Point­ers are simple.

Point­ers are not magical.

Point­ers are safe (as long as you use them only as allowed by the language)

(more…)