Berkeley CSUA MOTD:Entry 20839
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2001/3/19 [Computer/SW/Languages/C_Cplusplus] UID:20839 Activity:kinda low
3/18    For const vs. #define thread that someone deleted below, here's my
        answer.  #define is much more flexible than const. It lets you
        take in paramters, or generate a series of function calls (const
        will only let you create a value). #define also lets you refer to
        other #define's and will accept command line -D arguments passed
        into the compiler.
        \_ thanks, but I was really asking about the use of #define vs. const
           for the specific situation of constant values.  obviously #define
           can do things that const can't (like macros). (similarly, #define
           can do things typedef can't, but typedef clearly is preferable.)
           misha's answer was more what I was looking for.
        \_ There's No const. There's Only mconst.
2025/05/25 [General] UID:1000 Activity:popular
5/25    

You may also be interested in these entries...
2011/3/7-4/20 [Computer/SW/Languages/C_Cplusplus] UID:54056 Activity:nil
3/7     I have a C question.  I have the following source code in two identical
        files t.c and t.cpp:
                #include <stdlib.h>
                int main(int argc, char *argv[]) {
                  const char * const * p1;
                  const char * * p2;
	...
2010/6/4-30 [Computer/SW/Languages/C_Cplusplus] UID:53849 Activity:nil
6/4     Is this valid C++ code?
        std::string getStr(void) {
            std::string str("foo");
            return str;
        }
        void foo(char *s);
	...
2006/8/25-28 [Computer/SW/Languages/C_Cplusplus] UID:44153 Activity:nil
8/25    Dear C++ experts. Why would there be two "const" in the following
        method declaration?
        const bool ILikeMotd() const;
        \_ The first const refers to the data type returned.  The second
           const says the function doesn't modify an object's member variables.
           The first const in your example is bad, I believe; it should
	...
2006/7/28-8/2 [Computer/SW/Languages/C_Cplusplus] UID:43824 Activity:nil
7/27    In C/C++, how come some parameters have "mconst" before the type
        and some don't? I don't see how it changes anything. -newbie
        \_ If it's a pointer or reference, then you can't change the contents.
        \_ Nicely summarized here:
           http://www.parashift.com/c++-faq-lite/const-correctness.html
        \_ The answer is 47. -proud American
	...
2006/5/10-11 [Computer/SW/Languages/C_Cplusplus] UID:43010 Activity:nil
5/10    I'm trying to port a small project from builsing with MS Visual Studio
        to GCC in MinGW on windows.  Only 1 line is having a compile error.
        Using STL, the line
        if(hashmap->find(key)!=0)
        Has the following error:
        no match for `std::_Rb_tree_iterator<std::pair<const std::string, int>,
	...
2006/2/13-20 [Recreation/Computer/Games] UID:41824 Activity:moderate
2/13    What are your favorite old school computer games?
        \_ Recently rediscovered Pathways into Darkness http://pid.bungie.org
           \_ The skill levels for weapons was a cool innovation for a fps.
        \_ BEYOND CASTLE WOLFENSTEIN
        \_ Jumpman Jr.
        \_ The Pawn (C64 - 1985?), Conan (various 1986?)
	...