[previous] 0304 [next] [U] The address of an array declared 'register' may not be computed.
Explicitly undefined REFERENCE - ISO:C90-6.5.1 Storage-Class Specifiers - Semantics

An attempt has been made to use the address of an array declared with the register storage-class specifier.

Any object declared with register should be considered as having no physical address (although a particular implementation could treat a register declaration as being an auto declaration). If an array has no computable address then it is illegal to try to take the address either implicitly (through the conversion of an array name to a pointer) or explicitly with the unary & operator.

For example:


/*PRQA S 2017,2211,2711,3122,3132,3198,3199,3200,3203,3209,3408,3602,3625 ++*/

#include <string.h>

extern void foo(void)
{
    char          auc[4];
    register char ruc[4];
    char         *puc;

    puc = &auc[0];
    puc = &ruc[0];                       /* Message 0304 */

    strcpy(auc, "ABC");
    strcpy(ruc, "ABC");                  /* Message 0304 */
}


MISRA C:2012 Rules applicable to message 0304:

Rule-1.3  (Required) There shall be no occurrence of undefined or critical unspecified behaviour


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents