When I'm editing a source file and use content assist, then I don't want it to suggest variables/functions/etc. from other source files which I didn't include. It should only suggest things from the current file and from included headers. How can I make it so that the content assist won't suggest unreachable variables and functions? If there is no way to accomplish this, then that is frankly a ridiculous flaw for an otherwise excellent IDE.
The funny thing is that yesterday it seemed that I got it to work by moving the source files to a different folder, but today, if I don't list the source folder in "C/C++ General -> Paths and Symbols -> Source Locations", I get unresolved inclusions in the source file (the indexer won't even resolve standard library functions), and if I do list the folder, then I'm back to square one and content assist suggests unreachable variables/functions again.
CDT does not present unreachables in code completions. The issue you are facing is the definition of unreachable AFAICT.
In C, everything that is not static is "public" and can be called from anywhere else. No declaration is even necessary (although I would recommend -Wall -Werror
, but that is a separate discussion).
For example, consider file.c
with contents:
static void func_private1(void) {}
static void func_private2(void) {}
void func_public1(void) {}
void func_public2(void) {}
if you request completions for func_
in file.c
you get all the completions:
however, if you open another file and request completions for func_
you only get the public ones (non-static):
Now, in the other file, if you select func_public1
, then you can have CDT automatically add in the header file for it. You can do this with "organizing imports" Shift-Ctrl-O (Source menu -> Organize Imports).
You can control the behaviour of Organize Imports in the preferences (C/C++ -> Code Style -> Organize Imports)