User forums > Using Code::Blocks
2 functions in diffrent c files that have the same name
erezz:
--- Quote from: ollydbg on November 05, 2013, 02:21:57 am ---
--- Quote from: erezz on November 03, 2013, 03:12:12 pm ---I have a sample c::b project (attached) with 4 c files, each with a main() & foo1() functions. If I go to one of these files (e.g. b.c), select management->symbols, set view = current file's symbols, select "Global functions" and then click "foo1", it will go to foo1() in another file (sometimes it's a.c::foo1 or d.c::foo1). This sounds like a bug.
Erez
--- End quote ---
If the same function body is added, the later one will replace the former one. Why do we need to have two records for different functions.
If you have four header files which all have a same function declaration, and you have four source have the same function definition, how many records do you think CC need? You may expect there need 8 (this is a bit mass), but in fact, there is only ONE. CodeCompletion plugin's parser just merge all the function declaration and definition to only one record. So, you can switch from declaration and information very quickly, also keep the record database as small as it can.
BTW: CC just ignore your makefile, because it does not have the ability to parse and analysis the makefile structure and dependency rules. Anyway, if you want this feature, patches are welcome, I just don't have motion to do this. :)
--- End quote ---
Not sure that I understand your explanation. Note that I am a c::b user, not a developer, so I don't understand the internals of CodeCompletion plugin.
I think that it's legit to have a project that its output is multiple binaries where each binary is originated from a C file, and those C files may have functions with the same name. For a user that clicks b.c::foo1() and the IDE jump to d.c::foo1(), this is very not intuitive and strange. Still, sounds like a bug to me.
Erez
ToApolytoXaos:
erezz, please try to understand that in a C or C++ project, only one file has to use [define] main() and not in multiple sources. It's like trying to link two negative or positive sides of a magnet and wait them to merge.
If you are new to programming, I would suggest to read some good manual first and then experiment with IDEs.
What you are trying to test here will not work as it finds multiple definitions of main() function.
Always have in mind the following series of events: header file, implementation, definition [where your main() is located].
For brevity:
header file
--- Code: (header.h) ---#ifndef header_h_
#define header_h_
/* function prototype */
void demo(void);
#endif
--- End code ---
Implementation file
--- Code: (implementation.c) ---#include "header.h"
#include <stdio.h>
void demo(void) {
printf("this is our demo() function.\n";
}
--- End code ---
Use file where main() is located.
--- Code: (main.c) ---#include "header.h"
int main(void)
{
demo();
return 0;
}
--- End code ---
Any constructive criticism is always welcome, but please try to understand; this is not a forum for teaching the fundamentals of programming in any language.
erezz:
--- Quote from: ToApolytoXaos on November 05, 2013, 11:06:25 am ---erezz, please try to understand that in a C or C++ project, only one file has to use [define] main() and not in multiple sources. It's like trying to link two negative or positive sides of a magnet and wait them to merge.
If you are new to programming, I would suggest to read some good manual first and then experiment with IDEs.
What you are trying to test here will not work as it finds multiple definitions of main() function.
Always have in mind the following series of events: header file, implementation, definition [where your main() is located].
For brevity:
header file
--- Code: (header.h) ---#ifndef header_h_
#define header_h_
/* function prototype */
void demo(void);
#endif
--- End code ---
Implementation file
--- Code: (implementation.c) ---#include "header.h"
#include <stdio.h>
void demo(void) {
printf("this is our demo() function.\n";
}
--- End code ---
Use file where main() is located.
--- Code: (main.c) ---#include "header.h"
int main(void)
{
demo();
return 0;
}
--- End code ---
Any constructive criticism is always welcome, but please try to understand; this is not a forum for teaching the fundamentals of programming in any language.
--- End quote ---
Well, I'm writing C code for ~14 years already. This thread/bug report has nothing to do with teaching the fundamentals of programming.
If you take a look at the project that I attached, you will see that the custom Makefile generates 4 binaries, hence 4 main() functions are perfectly fine.
Erez
ToApolytoXaos:
--- Quote from: erezz on November 05, 2013, 12:12:19 pm ---Well, I'm writing C code for ~14 years already. This thread/bug report has nothing to do with teaching the fundamentals of programming.
If you take a look at the project that I attached, you will see that the custom Makefile generates 4 binaries, hence 4 main() functions are perfectly fine.
Erez
--- End quote ---
Well, for someone with approximately 14 years of experience in C, I would have expected you patching it in no time and then report it to Dev team lol.
Sorry Erez, but that response of yours sounded like troll.
I rest my case.
cheers
erezz:
--- Quote from: ToApolytoXaos on November 05, 2013, 12:45:47 pm ---
--- Quote from: erezz on November 05, 2013, 12:12:19 pm ---Well, I'm writing C code for ~14 years already. This thread/bug report has nothing to do with teaching the fundamentals of programming.
If you take a look at the project that I attached, you will see that the custom Makefile generates 4 binaries, hence 4 main() functions are perfectly fine.
Erez
--- End quote ---
Well, for someone with approximately 14 years of experience in C, I would have expected you patching it in no time and then report it to Dev team lol.
Sorry Erez, but that response of yours sounded like troll.
I rest my case.
cheers
--- End quote ---
1. I'm a c::b user, not a developer. I don't mind reporting c::b bugs (which I did with an example project that easily reproduces this bug), but I'm not the one to fix them.
2. Your response is irrelevant and offensive. If you have anything useful to contribute to this bug, please do. Else, I suggest that you allow other people to contribute to the conversation.
Erez
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version