Re: struct definition inside a function

2022-11-29 Thread Greg KH
On Tue, Nov 29, 2022 at 03:06:30PM +, 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


struct definition inside a function

2022-11-29 Thread Anuz Pratap Singh Tomar
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
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies