PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 28, 2022

[FIXED] What does #define Dbg(fmt,...) (0) mean? warning: expression has no effect

 April 28, 2022     c, c++, compiler-warnings, macros, warnings     No comments   

Issue

I am working on removing warnings from legacy code when I encountered the below macro

#define DISBALE_DEBUG
#ifdef DISBALE_DEBUG
    #define Dbg(fmt,...) (0) 
#else
    #define Dbg print
#endif

and used in the below code:

#ifdef __arm__
    Dbg("\n %s %s %d  %d \n", __FILE__, __FUNCTION__, __LINE__, mode);
#endif

for which i get the warning: ** expression has no effect**


Solution

If you enter the DISBALE_DEBUG #ifdef branch, the Dbg macro will be defined as a variadic macro which just consumes its variadic arguments and does nothing with them. I.e., a call such as

Dbg("\n %s %s %d  %d \n", __FILE__, __FUNCTION__, __LINE__, mode);

will resolve to

(0);

which, as the compiler accurately warns you about, has no effect.

If you enter the #else branch, on the other hand, the Dbg macro will just be a replacement, by the pre-processor, with print, meaning

 Dbg("\n %s %s %d  %d \n", __FILE__, __FUNCTION__, __LINE__, mode);

resolves to

print("\n %s %s %d  %d \n", __FILE__, __FUNCTION__, __LINE__, mode);

Now, given the information in your question, it is unclear what print(...) will resolve to, as it is not a standard function in C++ nor C. It's likely another variadic macro or a variadic function.



Answered By - dfrib
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing