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

debugging in keil

Hi,
I used to have all my functions above the main loop of my program earlier.recently i moved all the functions called by my mainloop into a another file and then included it before the main loop.

like this : #include "functions.c"

void main(void)
{...

}
My problem is when i now debug in keil, when i come to a function,the the yellow pointer arrow no longer jumps to the other file to the correct function.the is making debugging difficult cos i cant really follow the program any longer.
So i want to know if this is just something that cant be done, or is there some way to do this, put functions in another file and then still be able to watch the program using the keil debugger..
Thanks
Harsha

Parents
  • like this : #include "functions.c"

    Nooo!!

    That is not the way to do it! For one thing, it will give exactly the problem that you describe!

    Instead, compile your functions.c file separately, and have a so-called "header" file to provide the prototypes to your main 'C' source file; eg,

    functions.h

    extern void my_function( void );  // Prototype (declaration)
    

    functions.c

    #include "functions.h"            // Including this here allows the compiler to check that
                                      // the declaration matches the definition
    
    void my_function( void )          // Function definition
    {
        :
        // do stuff here
        :
    }
    

    main.c

    #include "functions.h"            // So that this file can "see" the Declarations
    
    void main( void )
    {
        :
        my_function();                // A call to the external function
        :
    }
    

    Just about every single Keil example illustrates this.

    This is standard, textbook 'C' stuff - nothing specifically to do with Keil;
    See: c-faq.com/.../decldef.html

    Note that the 'extern' on the function prototype is not strictly necessary;
    see: c-faq.com/.../extern.html

Reply
  • like this : #include "functions.c"

    Nooo!!

    That is not the way to do it! For one thing, it will give exactly the problem that you describe!

    Instead, compile your functions.c file separately, and have a so-called "header" file to provide the prototypes to your main 'C' source file; eg,

    functions.h

    extern void my_function( void );  // Prototype (declaration)
    

    functions.c

    #include "functions.h"            // Including this here allows the compiler to check that
                                      // the declaration matches the definition
    
    void my_function( void )          // Function definition
    {
        :
        // do stuff here
        :
    }
    

    main.c

    #include "functions.h"            // So that this file can "see" the Declarations
    
    void main( void )
    {
        :
        my_function();                // A call to the external function
        :
    }
    

    Just about every single Keil example illustrates this.

    This is standard, textbook 'C' stuff - nothing specifically to do with Keil;
    See: c-faq.com/.../decldef.html

    Note that the 'extern' on the function prototype is not strictly necessary;
    see: c-faq.com/.../extern.html

Children