Find the answer to your Linux question:
Results 1 to 4 of 4
Hello: How can I write a C preprocessor macro that is mapped to syslog versus fprintf depending on the OS. For instance, On Linux map to this. syslog(LOG_xyx, "STUFF %s ...
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Posts
    22

    C Preprocessor Macro for syslog/fprintf

    Hello:
    How can I write a C preprocessor macro that is mapped to syslog versus fprintf depending on the OS.

    For instance,

    On Linux map to this.
    syslog(LOG_xyx, "STUFF %s %d %x", str, avar, bvar);

    On Windows map to this. :
    fprintf(file, "STUFF %s %d %x", str, avar, bvar);

    Thanks,
    --B

  2. #2
    Just Joined!
    Join Date
    Mar 2008
    Location
    Chennai, India
    Posts
    26
    #ifdef LINUX
    #define macro(x,y,z,a,b) syslog(x, y, z, a, b);
    #else
    #define macro(x,y,z,a,b) fprintf(x, y, z, a, b);
    #endif


    Check this and do keep us posted.

    For reference, you can look into "The Complete C Reference- H.Schildt"

    cheers,
    Sarma

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    22
    Hi:

    I am worried about the variable arguments list. I don't want to have a different macro for every different combination of args to the syslog / printf.

    Any other suggestions.

    Thanks,
    --B

  4. #4
    Just Joined!
    Join Date
    Mar 2008
    Location
    Chennai, India
    Posts
    26

    Thumbs up Check the book I suggested

    Quote Originally Posted by bandeg View Post
    I am worried about the variable arguments list. I don't want to have a different macro for every different combination of args to the syslog / printf.
    --B
    C99 supports variable length macros also! Check the GCC manual and do keep us posted.

    Cheers,
    Sarma

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...