kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Song Zhi <hizhisong@outlook.com>
Cc: "kernelnewbies@kernelnewbies.org" <kernelnewbies@kernelnewbies.org>
Subject: Re: Why doesn't the GCC give any warning to these unused variables in the Linux kernel?
Date: Sun, 20 Feb 2022 10:09:05 +0100	[thread overview]
Message-ID: <YhIFMb9YBAsyLMp2@kroah.com> (raw)
In-Reply-To: <TYCP286MB08805725AFB579AC20631CFDB3399@TYCP286MB0880.JPNP286.PROD.OUTLOOK.COM>

On Sun, Feb 20, 2022 at 07:39:13AM +0000, Song Zhi wrote:
> Normally, the compiler warns if a variable is declared but is never referenced. In the Linux kernel source code, some unused functions and variables are marked __atrribute__((unused)).
> 
> 
> ==> https://livegrep.com/search/linux?q=__attribute__((unused))
> 
> 
> GCC, on the other hand, does not provide any warnings for these unused and unmarked variables like the integer flags in kernel/sched/idle.c#427<https://elixir.bootlin.com/linux/latest/source/kernel/sched/idle.c#L427> .
> 
> 
> Why?

Because we do not enable that build warning as it is mostly useless for
kernel code due to how different apis work inside the kernel.

Try enabling it yourself and see all of the noise that happens.

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      reply	other threads:[~2022-02-20  9:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-20  7:39 Why doesn't the GCC give any warning to these unused variables in the Linux kernel? Song Zhi
2022-02-20  9:09 ` Greg KH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YhIFMb9YBAsyLMp2@kroah.com \
    --to=greg@kroah.com \
    --cc=hizhisong@outlook.com \
    --cc=kernelnewbies@kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).