Macro expansion

This is a discussion on Macro expansion within the C Programming forums, part of the General Programming Boards category; I came across a code segment in open source, its like Code: #define pthread_exit(x)\ do {\ dbg("[%x] pthread_exit(" #x ")\n", ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    25

    Macro expansion

    I came across a code segment in open source, its like

    Code:
    #define pthread_exit(x)\
    do {\
    	dbg("[%x] pthread_exit(" #x ")\n", pthread_self());\
    	pthread_exit(x);\
    } while(0)
    does it mean that the macro pthread_exit(x) will be expanded
    multiple times (rather indefinite no of times) ...

    & also this code internally does not call exit() system call...
    I am confused how the exit is working in true sense

    plz comment...

    thanks...
    onebrother

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, macros aren't expanded recursively, so that code will work "as you'd expect it".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  4. L macro
    By George2 in forum C Programming
    Replies: 1
    Last Post: 08-20-2007, 10:24 AM
  5. Macro Program
    By daspope in forum Windows Programming
    Replies: 5
    Last Post: 04-25-2004, 05:02 AM

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