[previous] 0699 [next] [C] String literal used to initialize a pointer of incompatible type.
Constraint violations REFERENCE - ISO:C90-6.5.7 Initialization - Semantics, ISO:C90-6.3.16.1 Simple Assignment - Constraints

This is a constraint error

A string literal or a wide string literal is being used to initialize a pointer of incompatible type.

A string.literal is a constant of type 'array of char'. It can only be used to initialize an object of type "pointer to char" or "pointer to void", or an array of type char.

A wide string literal is a constant of type 'array of wchar_t'. It can only be used to initialize an object of type "pointer to wchar_t" or "pointer to void", or an array of type wchar_t.

For example:


/*PRQA S 878,2017,3122,3205,3408 ++*/

extern void foo(void)
{
  long *  p1 = "abc";           /* Message 0699 */
  short * p2 = L"abc";          /* Message 0699 */
}


MISRA-C:2004 Rules applicable to message 0699:

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