[previous] 0308 [next] Non-portable cast involving pointer to an incomplete type.
Pointers REFERENCE - ISO:C90-6.3.4 Cast Operators - Semantics

An expression of pointer type is being cast to a different pointer type and at least one of the types is incomplete.

Casts involving pointers to incomplete type should be conducted with particular caution in order to avoid the possibility of casting to a type with stricter alignment requirements. Be aware that the alignment requirements of a struct are dependent on the type of the first member within the struct.

Message 0308 is generated when a cast is identified which performs one of the following conversions:
  1. from a pointer to a complete type to a pointer to an incomplete type.
  2. from a pointer to an incomplete type to a pointer to a complete type.
  3. from a pointer to an incomplete type to a pointer to another incomplete type.

For example:


/*PRQA S 2017,3198,3199,3203,3227,3313,3408,3447 ++*/

extern struct ST1 *    pst1;            /* Pointer to incomplete type */
extern struct ST2 *    pst2;            /* Pointer to incomplete type */
extern unsigned long * pul;             /* Pointer to complete type   */


extern void foo(void)
{
    pst1 = (struct ST1 *)pul;           /* a) Message 0308 and 0310 */

    pul = (unsigned long *)pst1;        /* b) Message 0308 and 0310 */

    pst2 = (struct ST2 *)pst1;          /* c) Message 0308 and 0310 */
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents