Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6207679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:40:30+00:00 2026-05-24T05:40:30+00:00

I have a logging macro which in release mode becomes: #define LOG (void) So

  • 0

I have a logging macro which in release mode becomes:

#define LOG (void)

So statement

LOG("foobar %d", 0xbabecafe);

is expanded to

(void)("foobar %d", 0xbabecafe);

The problem is that the last expression produces an warning under gcc:

warning: left-hand operand of comma expression has no effect [-Wunused-value]

How can I change the logging macro such that no warning is issued? (Note, that I don’t want to add compiling flag -Wunused-value).

EDIT I see already a couple of answers involving (...). The same file is compiled under Minix which doesn’t support variadic macros. The best would be to have a C89 conforming solution. While your answer is correct (and I upvoted it), it is my fault that I didn’t include this small detail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:40:31+00:00Added an answer on May 24, 2026 at 5:40 am

    I think the old school way of dealing with this is to take advantage of double parens. Something like this:

    LOG(("message: %d", 10));
    

    Then for your macro, you define it like this:

    #define LOG(x) printf x
    

    or

    #define LOG(x) (void)0
    

    Because of the double parens, the pre-processor treats the whole inner paren as a single parameter. This at least used to work in visual studio.

    EDIT: I did a quick test, it works with gcc with -ansi, so it should be good:

    gcc -DNDEBUG -ansi -pedantic -W -Wall test.c -o test

    #include <stdio.h>
    
    #ifdef NDEBUG
    #define LOG(x) printf x
    #else
    #define LOG(x) (void)0
    #endif
    
    int main() {
        LOG(("message: %d\n", 10));
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a macro that might look as follows (from boost log library) #define
I have a logging table which has three columns. One column is a unique
I have the following need I have a logging table which logs som leads
In my application, I have a 'logging' window, which shows all the logging, warnings,
I have a problem logging onto a page and then using it with cURL.
I have a logging class which has operator<< overloaded. So I can do things
I want to realize logging in my project. I have macro, smth like __LOG_TRACE(lg,
I have a logging code which needs to be executed after all Threads s
I have a logging script which saves to file logs. I would like to
I have a little logging app (written in wxPython) that receives data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.