Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Why does IAR skip subroutine code while running project.

Status
Not open for further replies.

jp1390

New Member
Hello, I have encountered a problem with my code. I am programming a MSP430F425 microcontroller. I have written a program in C++ and I have noticed that some of my subroutines are being stepped over but are not being executed. This occurs even when I am using a step-by-step debugger.

For instance, I have a conditional statement if (Found > 0) and in the Watch window Found = 1, but when I debug the code, it simply skips over the subroutines inside the body of this condition.

Has anyone experienced this problem?

Thank you.
 
Compilers today are pretty smart in optimizing code. Try a different optimization level and see if the problem still exists. And post a more detailed example of your code.
 
I have defined subroutines in another source file and have declared as 'extern' in the corresponding header file. This subroutine is then called in my main source file in the 'main (void)' function. If I call this subroutine without placing 'void' infront of it, the compiler will report an error: Undefined external function. On the other hand, if I do place 'void' there is no error but the subroutine is skipped when the program is run.

Put void -> Skipped, no error
Neglect void -> Error
 
Post the part of the code you are talking about. Using 'extern' with functions (subroutines) doesn't make sense to me, it is usually used with external variables only. Use function declarations in the header file and definitions in source file.
 
In an header file "global.h":
Code:
extern void Ini_System();

In its source file "global.c":
Code:
#include <msp430x42x.h>
void Ini_System (void)
{
  WDTCTL= WDTPW +WDTHOLD;
}

In the "main.c":
Code:
#include "global.h"
main()
{
void Ini_System();
}
 
Last edited:
You are using the 'extern' keyword wrong. Change the code as follows.

In the header file "global.h":
Code:
void Ini_System(void);
Code in "global.c" seems to be ok.


In the "main.c":
Code:
#include "global.h"
main()
{
Ini_System();
}
 
Last edited:
Thank you. But the response is "Error[46]: Undefined external "Ini_System()" referred in main" after linking.
 
Post your code that gave that error: "Error[46]: Undefined external Ini_System()". Both, the .h file and .c file or part of them that are relevant.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top