[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:2012 Rules applicable to message 0699:

Rule-1.1  (Required) The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits


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