This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem when .c file is directly included in another file using #include

I have a Keil uv2 project which has two .c files namely main.c and add.c. The file main.c has function main. The add.c file has definition of function add. In main.c I included add.c using include statement like

#include "add.c"

Since .c file is directly included in main.c, the .M51 file generated by BL51 linker shows only one module detail, i.e. MAIN. Line number to hexaddress map information for add function is put under MODULE MAIN. Because of this I am facing problem in getting module info for add function correctly.
Instead of including .c file directly, if include .h file having just declaration of add function, the .M51 file will have correct information. it will have two MODULE details block one each for MAIN and ADD.
Can anyone has solution for this problem? Is there any settings I need to do to get correct function to source file linking information.

  • "Since .c file is directly included in main.c, the .M51 file generated by BL51 linker shows only one module detail, i.e. MAIN. Line number to hexaddress map information for add function is put under MODULE MAIN."

    Yes, that is entirely correct - that's what #include does!
    That's precisely why #including one .C file directly within another is generally a bad idea.

    "Because of this I am facing problem in getting module info for add function correctly."

    So don't do it, then!
    This is why we have tools called Linkers!

    "Instead of including .c file directly, if include .h file having just declaration of add function, the .M51 file will have correct information."

    Yes - that is the usual way to do it!

    "it will have two MODULE details block one each for MAIN and ADD."

    Correct!

    "Can anyone has solution for this problem?"

    What problem?
    It sounds like it's all working perfectly correctly!

  • Thanks Andt for the reply.
    My problem is, i am implementing debugging features such as Step Into, Step Out, etc. When StepInto add function is requested, i don't have information on in which source file the definition is available.
    If you have any logic to implement StepInto, please tell me. It will be very helpful. I am doing such implementations for the first time.

  • What do you mean by that?

    Do you mean you are writing you own debugger?

  • What kind of an answer is that?

    How can you expect useful replies if you don't supply sufficient information?

    Have you tried debugging one of the standard example projects that uses multiple source files?
    It sounds like your problem is not really in the debugging, but in correctly configuring the project in the first place!

  • Sorry for that.
    With standard project with multiple source files, my implementation works fine.
    As you said, the problem is in creating the project.
    The problem arises only when .c files are included directly using #include statement.

  • "The problem arises only when .c files are included directly using #include statement."

    As I said before, there is nothing you can do about that - it's the way the preprocessor works, isn't it?

    You do understand what the 'C' preprocessor does, don't you?
    Think about it...

  • Yes, I will. Thanks a lot for your inputs.

  • I have a 'catcher' like this

    void catch(void)
    {
    U8 spin;
    
      spin = 1:
      while (spin);
    }
    

    I realized that finding the point the catcher caught was a pain in my sittring muscle and changed to this where it is used

    catch();
    _nop_();
    

    this way, when catch catches I just set spin to zero in the ICE and step, step, (step) takes me to the place where it happened.

    Erik