C++: Macros

Discussion in 'C++' started by Web Developer, Aug 11, 2003.

  1. Hi,

    What are Macros in C++?


    WD



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003
    Web Developer, Aug 11, 2003
    #1
    1. Advertising

  2. Re: Macros

    "Web Developer" <> wrote in message
    news:3f373878$...
    > Hi,
    >
    > What are Macros in C++?
    >


    Paramatized textual substitutions in your source code.

    john
    John Harrison, Aug 11, 2003
    #2
    1. Advertising

  3. Web Developer wrote:

    > Hi,
    >
    > What are Macros in C++?
    >


    A macro is only slightly better than the "find and replace" function of
    most text editors. If I define a macro like this:

    #define SOME_MACRO some text

    Then every occurrence of SOME_MACRO in the source that follows will be
    replaced with "some text" (without the quote marks). There are
    exceptions, though. If the code that follows contains this:

    cout << "SOME_MACRO" << endl;

    The substitution does not occur in this case because the SOME_MACRO is
    inside a string literal.

    You can also have parameterized macros that act somewhat like inlined
    functions.

    Use of macros is discouraged in C++. They are dangerous and rarely
    necessary.

    You should be able to read all about this in your C++ book. Why didn't
    you? I guarantee you that you cannot learn C++ from a newsgroup.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
    Kevin Goodsell, Aug 11, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    80
    Views:
    2,356
    Stephen J. Bevan
    Nov 7, 2003
  2. Replies:
    1
    Views:
    429
    Marco Antoniotti
    Oct 7, 2003
  3. Replies:
    5
    Views:
    483
  4. Michael T. Babcock

    Re: Explanation of macros; Haskell macros

    Michael T. Babcock, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    505
    Michael T. Babcock
    Nov 3, 2003
  5. Andrew Arro

    macros-loop? calling macros X times?

    Andrew Arro, Jul 23, 2004, in forum: C Programming
    Replies:
    2
    Views:
    479
    S.Tobias
    Jul 24, 2004
Loading...

Share This Page