Project

General

Profile

Actions

Bug #2767

closed

NFD_LOG_INIT can cause unused variable warning

Added by Junxiao Shi over 9 years ago. Updated over 6 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Category:
Core
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
1.00 h

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.

Actions #1

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.

Actions #2

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.

Actions #3

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.

Actions #4

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.

Actions #5

Updated by Davide Pesavento almost 7 years ago

  • Start date deleted (04/23/2015)
Actions #6

Updated by Alex Afanasyev almost 7 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".

Actions #7

Updated by Davide Pesavento over 6 years ago

  • Status changed from New to Rejected
Actions

Also available in: Atom PDF