Compilation (gcc error)Type & Declaration5 min read

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.

Broken Pattern
int result = 2(3 + 4);
Corrected Pattern
int result = 2 * (3 + 4);
Illustrative diagnostic (not executed):error: called object '2' is not a function or function pointer

Local variable name shadows function identifier

Having int sum = 0; hides double sum(double, double) in the same block.

Broken Pattern
int add = 0;
add = add(2, 3);
Corrected Pattern
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 compiler
Read 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 compiler

Expected output from the corrected program

Reference output, not a live execution result.

6

Compiler & Sanitizer Diagnostic Matrix

Compiler / Runtime SymptomRoot CauseDiagnostic Flag / CheckCorrected Pattern
called object is not a functionMissing `*` in `2(x + 1)` or variable shadows fn-Wshadow -WallWrite `2 * (x + 1)` or rename shadowed local variable
function pointer parsed as returning pointerMissing parentheses `int *fp(int)`-WallWrite `int (*fp)(int)` for function pointers

▶ Load failing reproducer in Online C Compiler

Debugging Techniques and Commands

Shadowing Warnings
gcc -std=c17 -Wshadow -Wall -Wextra main.c -o app

Warns whenever a local variable hides a global variable or function.

Function Pointer Parentheses
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`.