void * used in a typedef, member, parameter, or variable

ID

c.maintainability.avoid_void_pointer

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Type Safety

Language

C / C++

Description

Reports void * used as the type of a typedef alias, a struct/class member, a function parameter, or a variable.

Rationale

A void * erases the pointee’s type, so the compiler can no longer catch a mismatched assignment, a wrong-type dereference after a cast, or an incorrect sizeof computed against the pointer. Every use downstream of the declaration has to be trusted to cast it back to the right type by convention alone, which is exactly the class of defect static and runtime type checking exist to catch.

The following code illustrates the pattern detected by this rule:

// FLAGGED: void * used in a typedef, member, parameter, or variable
typedef void *Handle;

Remediation

Use the concrete pointee type, or in C++ a template parameter, so the compiler enforces the type at every use site. Where a genuinely type-erased handle is required (e.g. crossing an ABI boundary), wrap it in a small typed struct instead of passing a bare void * around.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved