kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* struct definition inside a function
@ 2022-11-29 15:06 Anuz Pratap Singh Tomar
  2022-11-29 18:30 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Anuz Pratap Singh Tomar @ 2022-11-29 15:06 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 332 bytes --]

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;


return 0;
}
I'll appreciate any insight on this?
-- 
Thank you
Regards
Anuz

[-- Attachment #1.2: Type: text/html, Size: 663 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: struct definition inside a function
  2022-11-29 15:06 struct definition inside a function Anuz Pratap Singh Tomar
@ 2022-11-29 18:30 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-11-29 18:30 UTC (permalink / raw)
  To: Anuz Pratap Singh Tomar; +Cc: kernelnewbies

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-29 18:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-29 15:06 struct definition inside a function Anuz Pratap Singh Tomar
2022-11-29 18:30 ` Greg KH

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).