Path: utzoo!attcan!uunet!hsi!stpstn!lerman From: lerman@stpstn.UUCP (Ken Lerman) Newsgroups: comp.lang.c++ Subject: Re: #defines.... Message-ID: <5317@stpstn.UUCP> Date: 3 Jul 90 12:42:32 GMT References: <37786@genrad.UUCP> Reply-To: lerman@stpstn.UUCP (Ken Lerman) Organization: The Stepstone Corporation, Sandy Hook, CT 06482 Lines: 30 In article <37786@genrad.UUCP> slp@genrad.genrad.COM (Steven L. Peters) writes: [...] >With the C++ const, enum, and inline declarations, is it ever >necessary to use #define in a C++ program? Stroustrup emphatically >says in _The C++ Programming Language_ not to use them if you don't >have to. I'm wondering if you ever have to. I can't think of a >single time where you would be forced to use a #define over const or >inline... [...] > Stephen Peters The following is (more or less) taken from a real application #define GLOBAL(x) static char x[] = #x GLOBAL(reader); GLOBAL(writer); Generates: static char reader[] = "reader"; static char writer[] = "writer"; Without arguing the details, the point is that not every macro generates executable code. Functions cannot be used to create declarations, and "const" does not provide the terseness (be it good, bad, or indifferent) that macros provide. Ken