cancel
Showing results for 
Search instead for 
Did you mean: 

GCC: "each undeclared identifier is reported only once for each function it appears in"

Andrew Neil
Super User

I guess this is a GCC question, not specific to CubeIDE, but perhaps someone here knows?

 

Is there a way to make GCC report all the appearances of the undeclared identifier - not just the first?

I would find this more useful - rather than having to do a separate search to see if there are any other occurrences.

eg, It's not uncommon that I make the same spelling mistake in multiple places; or make a spelling mistake in the declaration, but spell all the references correctly; etc, ...

 

Googling hasn't helped me - it's just swamped by people explaining what "undeclared identifier" means.

I know what "undeclared identifier" means.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
5 REPLIES 5
Ozone
Principal II

I suppose not, I am familiar with this error on (and for) every platform I used gcc lately.

Instead I usually rely on a decent editor that allows me to mark and replace all instances of a string in a file.
AFAIK the "refactor" functionality in Eclipse can do the same.


@Ozone wrote:

I usually rely on a decent editor that allows me to...


But my point is that is (or may be) an unnecessary extra step.

I would like the compiler to show me all the occurrences - so that I can decide whether it warrants doing that. 

 


@Ozone wrote:

AFAIK the "refactor" functionality in Eclipse can do the same.


I find that is often the cause of these errors - the 'Refactor' didn't properly rename everything!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Jessica_Alleen
Visitor

From what I know, GCC doesn’t have a built-in option to report every single occurrence of an undeclared identifier. It only flags the first one per function as a way to avoid flooding the compiler output.

A practical workaround is exactly what Ozone suggested: rely on IDE/editor tools. Most modern IDEs (including CubeIDE, Eclipse, or even VS Code) have search/replace or refactor features that can highlight all instances at once. This usually ends up being more efficient than waiting for the compiler to list every error.

You can dig into the toolchain's source code, if you like ...

Andrew Neil
Super User

I should add that it says "each undeclared identifier is reported only once" even when there is only one.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.