![]() |
![]() |
0674 | ![]() |
||||
![]() | |||||||
| Constraint violations | REFERENCE - ISO:C90-6.5.7 Semantics, ISO:C90-6.3.16.1 Simple Assignment - Constraints | ||||||
This is a constraint error A pointer has been initialized with an expression of incompatible type. The initializer must be an expression which points to a compatible (possibly less qualified) type. For example:
/*PRQA S 750,753,759,2213,2216,3122,3132,3210,3205,3408,3447,3623,3625 ++ */
extern void foo(int p);
struct ST1 { int si; char sbuf[10];};
union UN1 { int ui; int uj;};
extern struct ST1 st1a;
extern union UN1 un1a;
extern int *pi;
extern unsigned char *puc;
extern int gi;
extern char cbuf[10];
extern void test(void)
{
char * pc1 = pi; /* 0674 */
char * pc2 = gi; /* 0674 */
char * pc3 = st1a; /* 0674 */
char * pc4 = un1a; /* 0674 */
char * pc5 = cbuf; /* OK, array lvalue decays to pointer */
char * pc6 = "abc"; /* OK, string literal is of type 'array of char' */
char * pc7 = puc; /* 0674 */
}
Note that according to ISO:C Standard 'char' and 'unsigned char' (or 'signed char') are distinct types, even though 'char' may be implemented as 'unsigned char' (or 'signed char'). For this reason message 0674 is generated for the last definition in the example above. If your compiler incorrectly allows such a conversion, you can use QA C option -foldplainchar (compiler personality) to mimic this behaviour.
MISRA-C:2004 Rules applicable to message 0674:
| 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 |