cancel
Showing results for 
Search instead for 
Did you mean: 

Arguments to main function

yeung-chris
Associate II
Posted on September 06, 2007 at 14:04

Arguments to main function

3 REPLIES 3
yeung-chris
Associate II
Posted on August 31, 2007 at 17:37

I'm currently working with an STR710FZ2T6 on an STR710-EVAL board. I am very new to MCU development and my background consists mostly of traditional C/C++ software development on x86 hosts.

For a few days now, I've been trying to figure out why I can't get a simple application to boot from the embedded flash (at 0x40000000) when I depress the Reset switch or reconnect power to the board. However I am able to run my app by sending a Startup/Go command to the board from the debugger. I am using the Realview Debugger software and an RVICE-ME.

I realized that the declaration of my main function included arguments, and that doesn't work, but if I change it to take in no arguments, then it boots on reset or from a power cycle just fine.

This won't run on reset or boot

Code:

int main (int argc, char** argv)

But this works

Code:

int main (void)

So I have a few questions which I'd be happy if anyone could shed some light on. What are the differences between running a program through the debugger versus running at boot time with regards to passing arguments into the main function? Is it possible to pass in arguments to the main function, either through the debugger or at system boot?

Thanks in advance.

kleshov
Associate II
Posted on September 01, 2007 at 05:41

With IAR EWARM software, the disassembly shows no difference in generated code for main() with or without arguments. It could be different with the RealView compiler. Try examining disassembly listings for main().

Normally it is not possible to pass arguments to main() in a microcontroller-based system. You certainly could modify the pre-main() code to communicate arguments to the system via some communications link and pass them to main(), but it is not practical and no-one ever does that.

yeung-chris
Associate II
Posted on September 06, 2007 at 14:04

Volius, thanks for the reply. That's what I was thinking as well; using arguments to main with a microcontroller doesn't make sense to me either.