Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Errors in editor when using #include to insert source code.(Errors in editor when using #include to insert source code.)
Errors in editor when using #include to insert source code. [message #1816322] Sat, 26 October 2019 21:57 Go to next message
Eclipse UserFriend
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 #1816325 is a reply to message #1816322] Sun, 27 October 2019 01:15 Go to previous messageGo to next message
Eclipse UserFriend
Would be helpful if you posted a short example.
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #1816340 is a reply to message #1816331] Sun, 27 October 2019 23:00 Go to previous messageGo to next message
Eclipse UserFriend
Difficult to answer without a small example that demonstrates the issue.

Just guessing, the Indexer and Syntax Analyzer try to read a file only once.
It assumes the included files are headers and not code.
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
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?


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 Go to previous messageGo to next message
Eclipse UserFriend
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.




Re: Errors in editor when using #include to insert source code. [message #1816405 is a reply to message #1816389] Tue, 29 October 2019 02:51 Go to previous messageGo to next message
Eclipse UserFriend
I'm still not sure why you are including all of your source into one file.
It would seem to me that the workspace is already cluttered with the included files.
So why not just compile them separately and link them to the final executable?
It's faster to compile only those sources which have changed.
You effectively have on large source file.
Everything is compiled for every build.
And is a maintenance nightmare.

Compiling the files individually will also circumvent the include issue you're experiencing.

===

To answer your questions,
The Indexer in Eclipse maintains a database of definitions within your project.
Basically it remembers function prototypes and macro definitions .

The indexer and syntax analyzer work together.
The syntax analyzer is a mini-parser
and is used to flag potential errors in your code.
The syntax tree is what it is building and examining.
It allows keeping a database of function names to aid searching among other things.


As for modular programming, it's way off topic for this forum.
Not to mention that it can be a deep and complicated subject.
You might want to start here:
https://www.geeksforgeeks.org/modular-approach-in-programming/
Google "modular approach in programming: for more.



Re: Errors in editor when using #include to insert source code. [message #1816525 is a reply to message #1816405] Wed, 30 October 2019 09:59 Go to previous messageGo to next message
Eclipse UserFriend
Quote:
I'm still not sure why you are including all of your source into one file.


This started as one big file. There never were any other source files. I just
created another file and put some of the code in there.

Quote:
You effectively have one large source file.
Everything is compiled for every build.
And is a maintenance nightmare.


Yes , I have one big file. It was becoming a hassle. That is why I wanted
to move some of it out of the workspace and into a separate file.
Things did not go as expected...

Quote:
Compiling the files individually will also circumvent the include issue you're experiencing.


It sounds like to me , what you are saying is that I need to create libraries to link to. I actually have never
made a library before. I do not really know how to set up eclipse and the compiler to do that. I am hoping
that making a header file for the exported source code , and compiling that source , followed by setting
the linking options to that newly created library would do such a thing. And of course using the #include
at the TOP of my original file. Does that sound right?

Quote:
You might want to start here:
https://www.geeksforgeeks.org/modular-approach-in-programming/


Thanks , I will definitely check that out.
Re: Errors in editor when using #include to insert source code. [message #1816529 is a reply to message #1816525] Wed, 30 October 2019 10:58 Go to previous messageGo to next message
Eclipse UserFriend
A library is just a file containing a bunch of object modules.
You can make a library but if the modules are project specific don't bother.
If you break the code up into pieces (modules)
Then you're.going to need to learn to use make.
Even if you are using a managed build (where Eclipse builds the makefile)
You still should learn how it works.

You could start here or google "gnu make tutorial" for more.
https://linuxhint.com/gnu-make-tutorial/
https://www.gnu.org/software/make/manual/make.html

[Updated on: Thu, 31 October 2019 18:03] by Moderator

Re: Errors in editor when using #include to insert source code. [message #1816624 is a reply to message #1816529] Fri, 01 November 2019 13:38 Go to previous message
Eclipse UserFriend
Thanks or pointing me in the right direction. I will go there. 8)
Previous Topic:samc20 and eclipse
Next Topic:Can I delete "refreshScope" configurations in the cproject?
Goto Forum:
  


Current Time: Tue Jun 24 23:01:46 EDT 2025

Powered by FUDForum. Page generated in 0.08068 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top