![]() |
![]() |
0757 | ![]() |
||||
![]() | |||||||
| Constraint violations | REFERENCE - ISO:C90-6.6.6.4 The return Statement - Semantics, ISO:C90-6.3.16.1 Simple Assignment - Constraints | ||||||
This is a constraint error This function is defined with a return type of pointer type but has a return expression which points to a more heavily qualified type. In an assignment operation, the type pointed to by the object on the left of the assignment operator must have all the type qualifiers of the type pointed to by the expression on the right. The same principle applies to a return expression. It is not permissible to return an expression of type "const TYPE *" (pointer to const TYPE) or "volatile TYPE *" (pointer to volatile TYPE) in a function defined with a return type of "TYPE *" (pointer to TYPE); to do so would permit the type qualification restrictions to be violated. On the other hand, it is perfectly legitimate to return an expression of type "TYPE *" in a function with a return type of "const TYPE *" or "volatile TYPE *" or even "const volatile TYPE *". For example:
/*PRQA S 2006,2214,3120,3132,3227,3408,3447,3602 ++ */
extern int *gpi;
extern const int *gpci;
extern volatile int *gpvi;
extern const volatile int *gpcvi;
int * fpi(int mode)
{
if (mode == 0) return(gpi); /* */
else if (mode == 1) return(gpci); /* Message 0757 */
else if (mode == 2) return(gpvi); /* Message 0757 */
else return(gpcvi); /* Message 0757 */
}
const int * fpci(int mode)
{
if (mode == 0) return(gpi); /* */
else if (mode == 1) return(gpci); /* */
else if (mode == 2) return(gpvi); /* Message 0757 */
else return(gpcvi); /* Message 0757 */
}
volatile int * fpvi(int mode)
{
if (mode == 0) return(gpi); /* */
else if (mode == 1) return(gpci); /* Message 0757 */
else if (mode == 2) return(gpvi); /* */
else return(gpcvi); /* Message 0757 */
}
const volatile int * fpcvi(int mode)
{
if (mode == 0) return(gpi); /* */
else if (mode == 1) return(gpci); /* */
else if (mode == 2) return(gpvi); /* */
else return(gpcvi); /* */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |