Kernel Newbies archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Anuz Pratap Singh Tomar <chambilkethakur@gmail.com>
Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Re: struct definition inside a function
Date: Tue, 29 Nov 2022 19:30:42 +0100	[thread overview]
Message-ID: <Y4ZP0lZATSyzvuse@kroah.com> (raw)
In-Reply-To: <CAJnfX5sHVS8TU_AONF9FhASdDqQWboHe1SYbaGc1f5UC0v74AA@mail.gmail.com>

On Tue, Nov 29, 2022 at 03:06:30PM +0000, Anuz Pratap Singh Tomar wrote:
> Hi all,
> I have not seen a struct define inside a function in kernel code and
> couldn't find any guidelines if it's permitted or frowned upon?
> 
> int fn(int i)
> {
>  struct my_struct {
> int var1;
> int var2
> }; /* is this allowed? */
> struct my_struct struct_local;

Yes, it is allowed, but usually you never want to do that in a kernel
function as structures are normally used across functions, not just only
in a single one.

Do you have a real-world example where you feel this pattern is the
best?

thanks,

greg k-h

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

      reply	other threads:[~2022-11-29 18:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 15:06 struct definition inside a function Anuz Pratap Singh Tomar
2022-11-29 18:30 ` 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=Y4ZP0lZATSyzvuse@kroah.com \
    --to=greg@kroah.com \
    --cc=chambilkethakur@gmail.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 read-only IMAP folder(s) and NNTP newsgroup(s).