From: Greg KH
Sent: 02 November 2020 20:11
On Mon, Nov 02, 2020 at 02:43:45PM -0500, Alex Deucher wrote:
On Mon, Nov 2, 2020 at 1:42 PM Deepak R Varma mh12gx2825@gmail.com wrote:
Initializing global variable to 0 or NULL is not necessary and should be avoided. Issue reported by checkpatch script as: ERROR: do not initialise globals to 0 (or NULL).
I agree that this is technically correct, but a lot of people don't seem to know that so we get a lot of comments about this code for the variables that are not explicitly set. Seems less confusing to initialize them even if it not necessary. I don't have a particularly strong opinion on it however.
The kernel coding style is to do it this way. You even save space and time by doing it as well :)
Uninitialised globals end up as 'named common' (variables that are their own code section - from FORTRAN) until the final link puts them into the .bss. Globals initialised to 0 go into the .bss of the object file being created.
So both end up in the final .bss.
If the code goes into a module you aren't allowed 'common' data in a module to every global must be initialised.
I'm surprised checkpatch complains.
David
- Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)