Errors in editor when using #include to insert source code. [message #1816322] |
Sat, 26 October 2019 21:57  |
Eclipse User |
|
|
|
I can successfully use the #include directive to add more source code to my main.c file.
I can compile the code and it works.
But , in the editor window , there are many errors listed.
In my example , there were 10 function definitions that I removed from my main.c file , and put in
a file called second.c .
Each one of these functions had a forward declaration in the main.c file.
In the editor , 4 of these forward declarations complain:
Unused Declaration of function
and are marked with errors.
In the editor , looking at second.c:
There are 1290 errors related to variables and constants that are defined by #include
directives , and definitions in the main.c file. EXAMPLE: The keyword NULL is defined
by including <stdio.h>. While this keyword is not highlighted as an error in the main.c file ,
it is in second.c.
I speculate that the editor is not treating both tabs as a single file , and whatever it is in eclipse
that detects these errors is parsing them separately. Is there a project specific setting that I
can use to tell eclipse to parse this as a complete file?
|
|
|
|
Re: Errors in editor when using #include to insert source code. [message #1816331 is a reply to message #1816325] |
Sun, 27 October 2019 11:20   |
Eclipse User |
|
|
|
I have made further progress.
I deleted the second.c source file and re made it with a right-click on the project in the
project explorer -> New -> Source file.
Then I gave the new source file a name. ( second.c )
Then I moved the selected procedures into second.c .
Then added #include "second.c" , at their original location in main.c .
Then I Right-Clicked on second.c in the project explorer
-> Resource Configurations ->Exclude from build.
This magically solved the failing symbol resolution.
I may have created the first second.c file outside of Eclipse and moved it to the
source folder for this project , and then added the #include , without "adding new source file" .
I do not know why this would matter , maybe you can tell me if it does or not.
In any event , the symbol resolution is working again.
But , the procedure declarations at the top of main.c are still marked as:
"Unused Declaration of function function_name."
Further inspection has revealed that if procedures that are declared in main.c , that reside in
second.c , are not used in main.c , then it is marked as Unused. This should not be the case. An
#include directive should be a cut and paste of source into the main.c file.
My expectation is that the compiler should see the external source code as inline with the
main.c code.
Any suggestions?
|
|
|
|
Re: Errors in editor when using #include to insert source code. [message #1816389 is a reply to message #1816340] |
Mon, 28 October 2019 17:56   |
Eclipse User |
|
|
|
That response indicates to me how much I do not know about what I am doing.
After reading it , I have several more questions:
What is an Indexer?
What is a Syntax Analyzer?
What is a Syntax tree?
What is a self-contained module?
I did some reading and now have a basic understanding of most of it.
I need to ask a few things to properly understand your response:
Quote:Just guessing, the Indexer and Syntax Analyzer try to read a file only once.
What is "a file" in this context? Does this mean the original source file and any includes?
Quote:It assumes the included files are headers and not code.
" It " means the Indexer and Syntax Analyzer i am assuming. So:
Does that mean that when using a #include , that it can only be a header file and not more source
code? If that is the case I am breaking some kind of rule then.
Quote:The Syntax Analyzer in Eclipse is not a compiler and it doesn't remember syntax trees.
You seem to be asking Eclipse to act as a compiler.
I am unsure what a syntax tree is. But , from your first statement here, I do understand that
Eclipse does not remember them , and that a compiler would. And that if I expect it to do so
would be to expect Eclipse to act like a compiler. I suppose that may be true , I use Eclipse
to compile my source code into executeables. I do see it as "what compiles my source" , but
I do know that it is a front end to my compiler , in my case GCC.
Quote:Reading all the source every time defeats the idea of indexing.
The normal method is to have code in self-contained modules which are later linked.
Is there some reason for including the code instead of using linked modules?
I am assuming here that module is a library , and that what you mean is that you should
compile your source code , make a header file , include the header in you new project ,
and link to that library. If that is the case, then I understand what you meant. My project
source code is no where near having compiled libraries yet. The source is constantly
changing on a day to day basis. The reason I am trying to include source code in this
manner is to get it out of the way so I can have an uncluttered workspace , and contain
the source for related routines in one place. The code folding options are causing more
pain that usefulness , code opens by itself when new lines of code are added elsewhere,
the buttons that open the code randomly disappear and I cant open sections. And if I turn it
off , I have a 3000 mile long source file that takes a huge amount of scrolling to get to places
in the code I need to jump to. So , I thought , just group source code into little files of related
routines , and include them. Then I would have a small source file to work with all the time.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08068 seconds