Initialisation of arrays of floats - 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.9 Initialization (https://forum.misra.org.uk/forumdisplay.php?fid=164) +---- Thread: Initialisation of arrays of floats (/showthread.php?tid=1357) |
Initialisation of arrays of floats - sdcandy - 19-07-2017 Rule 9.3 in MISRA C:2012 has an exception which states "An initializer of the form { 0 } may be used to explicitly initialize all elements of an array object or subobject". This means that something of the form is acceptable: Code: uint32_t x[3] = { 0 }; When using floating point types is it also acceptable to use something of the form: Code: typedef double float64_t; -Andy. Re: Initialisation of arrays of floats - misra-c - 28-09-2017 { 0 } is a MISRA-C 2012 exception, which permits the initialization of the elements of any array to zero. Initialisating an array of double with { 0.0 } is non-compliant, unless the array has only one element. Code: float64_t array_a[10] = { 0.0 }; // non-compliant |