Open-before-use
Posted Apr 1, 2008 10:56 UTC (Tue) by
epa (subscriber, #39769)
Parent article:
How Do I Make This Hard to Misuse?
It's hard for the compiler to ensure that the user calls your "open" routine before your other routines, but an "assert()" can at least get you to this level.
In C++ it would be normal practice to make the 'open' routine the constructor, so you automatically have to call it first before any member functions. But you can do this in C too, if your functions all take a handle argument and open() is the only one that generates such a handle.
(
Log in to post comments)