[previous] 0682 [next] [C] Initializer for object of a character type is a string literal.
Constraint violations REFERENCE - ISO:C90-6.5.7 Initialization - Semantics, ISO:C90-6.3.16.1 Simple Assignment - Constraints

This is a constraint error

An object of type 'char', 'signed char', 'unsigned char' or 'wchar_t' is being initialized with a string literal. A string literal has type 'array of char' and can only be used to initialise an object of compatible pointer type or array type. An object of type 'char' can only be initialised with an integral constant expression, for example a character constant.

For example:


/*PRQA S 753,2017,2211,3122,3132,3205,3408,3604,3625 ++*/

extern void foo(void)
{
    char h1     = "Y";         /* Message 0682 */
    char h2     = "hello\n";   /* Message 0682 */
    char buf[2] = "Y";         /* OK           */
    char *pc    = "hello\n";   /* OK           */
}


MISRA-C:2004 Rules applicable to message 0682:

Rule  1.1  (Required) All code shall conform to ISO/IEC 9899:1990 C programming language, ISO 9899, amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2: 1996192


See also:

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