How to tell if a field in c struct is initialized?
Hi, I come across this code: http://elixir.free-electrons.com/linux/latest/source/drivers/scsi/scsi_netli... other fields such as .cbmutex, .bind, etc are not initialized. Since the object =cfg= is of automatic storage, I wonder how the kernel tells if a field is initialized or its value is just some random bits on the stack? -- Best, Shiyao
On Fri, Dec 08, 2017 at 08:47:42PM +0800, Shiyao MA wrote:
Hi,
I come across this code: http://elixir.free-electrons.com/linux/latest/source/drivers/scsi/scsi_netli...
other fields such as .cbmutex, .bind, etc are not initialized.
Since the object =cfg= is of automatic storage, I wonder how the kernel tells if a field is initialized or its value is just some random bits on the stack?
The fields are initialized to zero. It's a C specification requirement. Hope this helps, greg k-h
Thanks for your reply. Best, On Fri, Dec 8, 2017 at 9:11 PM, Greg KH <greg@kroah.com> wrote:
On Fri, Dec 08, 2017 at 08:47:42PM +0800, Shiyao MA wrote:
Hi,
I come across this code: http://elixir.free-electrons.com/linux/latest/source/drivers/scsi/scsi_netli...
other fields such as .cbmutex, .bind, etc are not initialized.
Since the object =cfg= is of automatic storage, I wonder how the kernel tells if a field is initialized or its value is just some random bits on the stack?
The fields are initialized to zero. It's a C specification requirement.
Hope this helps,
greg k-h
-- Best, Shiyao
participants (2)
-
Greg KH -
Shiyao MA