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.

Parents
  • "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!

Reply
  • "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!

Children