Subj : Re: Win98 error To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Fri Mar 12 2004 03:14 pm Thomas Maeder [TeamB] wrote: >Bob Gonder writes: > >>>> #define nmax 100 > >const int nmax=100; > >is not a variable. It's a const. If used like a macro can be used, it has an >"immediate" value, like a macro. Additionally, it's address can be taken. Hmmm.. how can you take the address of an immediate (non-existant) variable? I would suppose it'd get pushed on the stack, then the stack address used. At which point, it _is_ a variable. > And it can belong in a namespace, avoiding to contribute to global namespace >"pollution". My personal take is that namespaces are a crock. But then, I string together units (#include "unit2.c") into what might be thought of as a "module namespace" with only "global public" names non-static. Suppose namespaces would allow me to compile the sub-modules seperately. Not sure I'd want that headache though. Maybe in a team environment. >Short, it has *all* the uses the macro version has; then, it has more uses; >but it hasn't any of the problems macros have. Can it also be used in a header file by several modules? (I supposed I _could_ try it and find out.....) And... I haven't run into any "problems" with macros. > I'd consider defining nmax as a macro a bug. You'd probably tisk at a lot more of my code too... You were likely schooled in C. My U didn't offer C, just Fortran, Algocol, Cobol, Basic, and several ASMs (there might have been a Snobol, but didn't take it) I did some minor tinkering with C/C++ when BC++2.0 came out, but only started seriously using it 3 years ago, converting my business apps from Asm. So, I'm not indoctrinated with the "politically correct" way to write C code. I've learned by pattern recognition.. ie: void dosomething( const int i ) { char array[i]; /* wrong (isn't it?)*/ looks very much like const int i = 100; char array[i]; /* ok */ It's the same words, but different meanings. I don't like to use "magic" in compilers. Too often it bites ya. >It's *not* a variable. It's a const. But it "looks" like a variable. It has the syntax of a variable. It acts like a variable (except the writting to it part). (Some crack about ducks goes here)... .