Newsgroups: comp.lang.c++
Path: utzoo!utgpu!cunews!csi.uottawa.ca!news
From: hitz@sim5.csi.uottawa.ca (Martin Hitz)
Subject: macros (was: const vs. static in class declaration)
Message-ID: <1991Apr5.211511.19618@csi.uottawa.ca>
Summary: SOmetimes useful
Keywords: macros, inline
Sender: news@csi.uottawa.ca
Nntp-Posting-Host: sim5
Organization: University of Ottawa
References: <3864@island.COM> <1991Apr3.202015.7402@csi.uottawa.ca> <657@taumet.com>
Distribution: na
Date: Fri, 5 Apr 91 21:15:11 GMT

In article <657@taumet.com> steve@taumet.com (Stephen Clamage) writes:
>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.  

I do understand most ARRRRGGGGHHHuments in favor of inline functions,
however, an inlined DIM function couldn't be used where compile-time
expressions are needed (at least not with g++ and Zortech), as in

	int x[DIM(y)];

That's why I still use macros (from time to time).

Martin Hitz (hitz@csi.UOttawa.CA)
