Thread: Visual Studio won't be able to compile MACRO function with local variable?

  1. #1
    Registered User
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    4

    Visual Studio won't be able to compile MACRO function with local variable?

    Hi, geeks:

    It seems Visual Studio is not able to build the following MACRO with a new local variable
    __x
    allocated.

    Code:
    #define FAST_SCALE_PQ(X,P,Q) ({						\
       unsigned __x = (X);							\
       func1( __x * (P), __x, __x, (Q) );				\
    })
    GCC seems to work fine. Any work around?

    Thank you very much.


    Best Regards
    Pei

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why do you have a pair of braces inside a set of parenthesis?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    4
    I now changed it to
    Code:
    #define TEST_FAST_SCALE_PQ(X,P,Q)   \
        func( ( (X) * (P) ), (X), (X), (Q) );
    it still failed....

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What do you mean "it failed"?


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The failure would depend on how you are using the macro, which you have not described. What arguments are you supplying as X, P, and Q?

    On your case with a variable named __x, the C standard explicitly reserves identifiers starting with two underscores. Such identifiers therefore should be avoided in user-implemented code (including within macros).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile C in Visual Studio
    By Keylac in forum C Programming
    Replies: 6
    Last Post: 11-26-2009, 09:55 PM
  2. Replies: 2
    Last Post: 07-08-2008, 03:45 AM
  3. Debug/Compile C in VISUAL STUDIO --need help!
    By bcgabriot in forum C Programming
    Replies: 4
    Last Post: 05-21-2007, 02:49 AM
  4. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM
  5. visual studio won't compile what i modify
    By Shadow12345 in forum C++ Programming
    Replies: 7
    Last Post: 11-28-2002, 09:27 PM