C is a general-purpose, procedural programming language that provides low-level access to system memory. It is known for its efficiency, portability, and power, making it ideal for system programming.
C Anti-Patterns Overview
Not Checking Return Values
Buffer Overflows
Memory Leaks
Using gets() Function
gets()
as it has no bounds checking. Use fgets()
or other bounded input functions instead.Integer Overflow
Using Uninitialized Variables
Not Using const for Read-Only Parameters
const
for function parameters that should not be modified to communicate intent and enable compiler optimizations.Using Magic Numbers
Using Global Variables
Not Using Header Guards
Using void* Without Type Checking
void*
without proper type checking. Use tagged unions or other type-safe alternatives when possible.Not Using Function Prototypes
Not Checking for NULL After Memory Allocation
malloc
return NULL before using the allocated memory.Using strcpy and strcat Unsafely
strcpy
and strcat
. Use bounded alternatives like strncpy
and strncat
, or better yet, use safer string handling libraries.Using Switch Statements Without Default Case
Not Using Static Analysis Tools
Using Macros Instead of Inline Functions
Not Using Defensive Programming
Not Using Proper Error Codes