Like Tree2Likes
  • 2 Post By phantomotap

can pass half parentheses as macro agument?

This is a discussion on can pass half parentheses as macro agument? within the C Programming forums, part of the General Programming Boards category; Hi, Is there any way to pass a left parenthese or right parenthese as an argument to a function-like macro? ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    48

    can pass half parentheses as macro agument?

    Hi,

    Is there any way to pass a left parenthese or right parenthese as an argument to a function-like macro?

    Thanks,

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    You can pass it in a normal function as a char or as it's ascci code --> '('

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    thank you. I'm just curious when I read about cpp macro seems no way to implement that.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    if this is what you want, it is possible with a trick. this seems to work. if you just put a literal non-string ) as the argument to M, the parser sees it as a closing paren and pukes. But if you do it with the #define P then that all gets substituted in before being parsed.
    Code:
    #define P )
    #define M(a) f(a
    
    void f(void)
    {
    }
    
    int main(int argc,char *argv[])
    {
    	M(P);
    	return 0;
    }
    the Visual C preprocessor outputs this
    Code:
    C:\home\dh0072\x\x1>cl /E x1.c
    Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    x1.c
    #line 1 "x1.c"
    
    
    
    void f(void)
    {
    }
    
    int main(int argc,char *argv[])
    {
            f();
            return 0;
    }

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    @dmh2000, yes, great, that does the trick!

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,261
    O_o

    What are you trying to do?

    Soma
    iMalc and Click_here like this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parentheses solver
    By yangss in forum C Programming
    Replies: 27
    Last Post: 09-01-2010, 02:41 PM
  2. Monitor displaying half good / half bad
    By Hiyo in forum Tech Board
    Replies: 3
    Last Post: 12-16-2006, 09:06 PM
  3. Parentheses in IF statements.
    By thetinman in forum C++ Programming
    Replies: 11
    Last Post: 11-30-2005, 03:08 PM
  4. Half Humanoid, half Chimpanzoid
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-19-2004, 04:23 PM
  5. Difference between macro and pass by reference?
    By converge in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2002, 04:20 AM

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