MISRA Discussion Forums
Rule 11.9 : Global initialization of pointers - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.11 Pointer type conversions (https://forum.misra.org.uk/forumdisplay.php?fid=166)
+---- Thread: Rule 11.9 : Global initialization of pointers (/showthread.php?tid=1165)



Rule 11.9 : Global initialization of pointers - Akhil - 13-03-2015

In this case :

1. int *ptr ; // Is this compliant or non compliant
2. void foo()
3. {
4. /* Do Something. */
5. }

Global variables are initialized to 0 by default.
This means ptr is initialized to 0 automatically by compiler.

Ques : Is line 1 compliant or non compliant to Rule 11.9.

Does this rule also enforce initializing ptr to NULL for global pointers. ?


Re: Rule 11.9 : Global initialization of pointers - misra-c - 27-03-2015

Rule 11.9 is not applicable to default initialisations. Your global declaration of "int *ptr;" does not violate rule 11.9.