a #define problem

This is a discussion on a #define problem within the C Programming forums, part of the General Programming Boards category; Code: #define tip(expr) printf(#expr"=%f\n",expr) if i make a tip(a+b) it prints some random number... how can i make it work? ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    a #define problem

    Code:
    #define tip(expr) printf(#expr"=%f\n",expr)
    if i make a tip(a+b) it prints some random number... how can i make it work?

    thank you!

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Australia - Melbourne
    Posts
    63
    your double quote is in the wrong place that's one thing, and your also missing a semicolon . what it should be given below

    Code:
    #define tip(expr) printf("#expr=%f\n",expr);
    i hope that's what you asked for

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    post your code because it works for me.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    Code:
    #define tip(expr) printf(#expr"=%f\n",expr)
    #include<stdio.h>
    
    int main()
    {
            tip(1+4);
            return 0;
    }
    Code:
    root@pamblica:~/prog# gcc -o test test.c
    root@pamblica:~/prog# ./test
    1+4=-0.073272
    root@pamblica:~/prog# ./test
    1+4=-0.146464
    root@pamblica:~/prog# ./test
    1+4=-0.225375

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Australia - Melbourne
    Posts
    63
    instead of tip(1+4); use tip(1.0+4.0);

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    yes... thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 05:33 AM
  2. Help me with function call
    By NeMewSys in forum C++ Programming
    Replies: 16
    Last Post: 05-22-2008, 01:53 PM
  3. C problem with legacy code
    By andy_baptiste in forum C Programming
    Replies: 4
    Last Post: 05-19-2008, 06:14 AM
  4. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 11:52 AM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 05:05 PM

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