Fix “called object is not a function or function pointer” in C
Because C requires explicit multiplication `*` and resolves inner block variables before file-scope functions, both `y = x(a + b);` and declaring a local `int sum = 0;` before calling `sum(1, 2)` make the compiler treat an integer as a callable function.
Quick Fix Summary
Insert missing * multiplication operators (2 * (a + b)), rename local variables so they never shadow function names, and verify function pointer declarations use (*fp)(args).
Why This Error Happens
Variable shadowing inside blocks
C permits a local int print = 1; inside main() to shadow a top-level function print(). Subsequent print(); in that scope resolves to int print and fails.
Algebraic shorthand missing *
Mathematical notation like a(b + c) parses as calling identifier a with argument b + c, never multiplication.
Top Root Causes & Specific Code Fixes
Algebraic parentheses without explicit *
Writing a(b + c) is parsed as a function call rather than multiplication.
int result = 2(3 + 4);int result = 2 * (3 + 4);Local variable name shadows function identifier
Having int sum = 0; hides double sum(double, double) in the same block.
int add = 0;
add = add(2, 3);int total = add(2, 3);Complete Broken and Corrected Programs
Compare the source before running it. The broken program is intentionally incorrect; its behavior can depend on the compiler and platform.
Read the broken program
#include <stdio.h>
int twice(int n) { return n * 2; }
int main(void) {
int twice = 5;
printf("%d\n", twice(3));
return 0;
}Open broken program in compilerRead the corrected program
#include <stdio.h>
int twice(int n) { return n * 2; }
int main(void) {
int value = twice(3);
printf("%d\n", value);
return 0;
}Open corrected program in compilerExpected output from the corrected program
Reference output, not a live execution result.
6Compiler & Sanitizer Diagnostic Matrix
| Compiler / Runtime Symptom | Root Cause | Diagnostic Flag / Check | Corrected Pattern |
|---|---|---|---|
| called object is not a function | Missing `*` in `2(x + 1)` or variable shadows fn | -Wshadow -Wall | Write `2 * (x + 1)` or rename shadowed local variable |
| function pointer parsed as returning pointer | Missing parentheses `int *fp(int)` | -Wall | Write `int (*fp)(int)` for function pointers |
Debugging Techniques and Commands
gcc -std=c17 -Wshadow -Wall -Wextra main.c -o app
Warns whenever a local variable hides a global variable or function.
gcc -std=c17 -Wall main.c -o app
Verify `int (*cb)(int)` syntax instead of `int *cb(int)`.
Frequently Asked Questions
Why does -Wshadow help prevent this?
Enabling `-Wshadow` warns immediately at variable declaration time if you reuse a global symbol name locally.
Can function names and variables share a namespace in C?
No. In C, functions and variables occupy the ordinary identifier namespace, unlike struct tags.
How do I fix int *fn(int) vs int (*fn)(int)?
`int *fn(int)` declares a function returning `int *`; parentheses around `(*fn)` make `fn` a pointer to a function returning `int`.