macros

This is a discussion on macros within the C++ Programming forums, part of the General Programming Boards category; in this code: Code: #define something(n) afunction() would it be posssible to use n as an integer in afunction()?...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    macros

    in this code:
    Code:
    #define something(n) afunction()
    would it be posssible to use n as an integer in afunction()?
    "Computers aren't intelligent, they only think they are."

    **infected by Blizzarddog**
    I am a signature virus. Please add me to your signature so that I may multiply

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    yes

    macros do little more than replace code.

    So,

    #define something(n) afunction(n)

    causes:

    something(i);

    to be the same as

    afunction(i);
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    27
    in that case could you tell me what i am doing wrong here?

    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    #define something(n) funct()
    void funct(void)
    {
        cout<<n;
    }
    
    int main()
    {
        something(1);
        getch();
        return 0;
    }
    "Computers aren't intelligent, they only think they are."

    **infected by Blizzarddog**
    I am a signature virus. Please add me to your signature so that I may multiply

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    yes, your "funct()" does not take a parameter n. Why are you using a macro for this anyway?

    ie:

    void funct(int n).....

    In addition, your macro doesn't pass it in to funct as my previous example shows
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    27
    ok thanks that worked, i didnt finish reading your post (not too bright today)
    >Why are you using a macro for this anyway?
    i was trying to think of a simple example as it would be easier to not have to read through lines of unrelated code
    "Computers aren't intelligent, they only think they are."

    **infected by Blizzarddog**
    I am a signature virus. Please add me to your signature so that I may multiply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Order of execution of preprocessor macros
    By DL1 in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 06:52 PM
  2. Pre-processor macros causing segfaults
    By nempo in forum C++ Programming
    Replies: 6
    Last Post: 02-10-2009, 01:35 AM
  3. Macros inside of macros
    By Chewie8 in forum C Programming
    Replies: 2
    Last Post: 02-24-2008, 02:51 AM
  4. Macros vs Inline Functions
    By vb.bajpai in forum C Programming
    Replies: 4
    Last Post: 08-02-2007, 11:51 AM
  5. template fn replacements for msg macros
    By Ken Fitlike in forum Windows Programming
    Replies: 17
    Last Post: 10-30-2002, 06:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21