Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: const vs. static in class declaration Keywords: const, static, class constants Message-ID: <657@taumet.com> Date: 4 Apr 91 17:59:43 GMT References: <286@dayton.stanford.edu> <139@grenada.island.COM> <3864@island.COM> <1991Apr3.202015.7402@csi.uottawa.ca> Distribution: na Organization: Taumetric Corporation, San Diego Lines: 25 hitz@sim5.csi.uottawa.ca (Martin Hitz) writes: >However, I *do* use a define in such a case to avoid declaration of > N inline functions for N arrays: >#define DIM(array) (sizeof(array)/sizeof(*array)) ARRRRGGGGHHH! Use inline member or non-member functions to do this. They will be evaluated at compile time by any decent compiler, and it avoids the nasty problems of mismatched types and unscoped names endemic to macros. IMHO this far outweighs the few minutes spent declaring the inline functions. (There is no other penalty, since the functions can all have the same name, "DIM" if you like.) =========== class illumination { BRIGHTEN(int); DIM(int); // illegal due to macro }; =========== char *ray; // legal but misleading -- proper set of inline int sz = DIM(ray); // functions would give error at compile time =========== -- Steve Clamage, TauMetric Corp, steve@taumet.com