Bug #2767
closedNFD_LOG_INIT can cause unused variable warning
0%
Description
When NFD_LOG_INIT
declares a logger instance, if the module isn't using the logger (yet), some compiler may detect the logger instance as an unused variable and generate warning.
__attribute__((__unused__))
should be applied to the declaration to suppress such warning.
Updated by Davide Pesavento over 9 years ago
In fact, I'm not sure I want to suppress the warnings. Unused loggers should be deleted because they shouldn't be shown in the list of modules. Moreover, there is a (small) performance cost in initializing unused loggers.
For the scenario in which a logger is used only by conditionally compiled code (e.g. #ifdef
), it is a rare corner case, I don't think it has happened yet in NFD. So we can simply ignore it, and deal with it (when/if it occurs) by simply wrapping the macro with an appropriate #ifdef
. Alternatively we can introduce a NFD_LOG_INIT_MAYBE_UNUSED
macro for such cases.
Updated by Junxiao Shi over 9 years ago
Unused loggers should be deleted because they shouldn't be shown in the list of modules.
When a module exists, it's okay to show it in the list of modules, even if it doesn't actually produce any logs.
Moreover, there is a (small) performance cost in initializing unused loggers.
This is a O(1) cost, not a per-packet cost.
For the scenario in which a logger is used only by conditionally compiled code (e.g.
#ifdef
), it is a rare corner case, I don't think it has happened yet in NFD. So we can simply ignore it, and deal with it (when/if it occurs) by simply wrapping the macro with an appropriate#ifdef
.
Consider the following case:
#ifdef LINUX
NFD_LOG_DEBUG(...)
#endif
#ifdef OSX
NFD_LOG_DEBUG(...)
#endif
The logger declaration condition would be more and more complex.
Alternatively we can introduce a
NFD_LOG_INIT_MAYBE_UNUSED
macro for such cases.
No, it's unnecessary.
Updated by Davide Pesavento over 9 years ago
Junxiao Shi wrote:
Moreover, there is a (small) performance cost in initializing unused loggers.
This is a O(1) cost, not a per-packet cost.
There is also a memory cost.
For the scenario in which a logger is used only by conditionally compiled code (e.g.
#ifdef
), it is a rare corner case, I don't think it has happened yet in NFD. So we can simply ignore it, and deal with it (when/if it occurs) by simply wrapping the macro with an appropriate#ifdef
.[...]
The logger declaration condition would be more and more complex.
As I said this is a corner case that hasn't happened yet, and might not ever happen. You're trying to solve a problem that doesn't exist.
Updated by Junxiao Shi over 9 years ago
- Target version deleted (
v0.4)
This problem should be solved when it occurs for the first time.
Target Version is cleared for now.
Updated by Alex Afanasyev over 6 years ago
I will concur with Davide. If logging module is not exercised, it should not be initialized. There is no value having it for the sake of having it. Whenever you add log statement, just add proper NDN_LOG_INIT
.
I'd vote to reject this "bug".
Updated by Davide Pesavento over 6 years ago
- Status changed from New to Rejected