passing arguments in functions

Hi, I have the following problem:
I am trying to work my way into some os c programm, and being not qite a pro in programming, I have a hard time with it. I did check the books and the internet but don`t find an answer to my problem.
My working place is mplab Ide v8.9with a project tree consisting mainly of headers and source files, and there is one main file. The source files consist of definitions, declerations and functions.
So I write a function in one of the sourcefiles, with a prototype, and when I call the function inside an other function, no arguments seeme to be passed, either any return value appears.

Basically I don`t quite understand the entire tree, how all the source files work together with the main, wich is rather small.

here`s the main:

include "defines.h"

if (USE_TELELOG == 1)

include "telemetry_log.h"

endif

if (USE_USB == 1)

include "preflight.h"

endif

if (USE_CONFIGFILE == 1)

include "config.h"

endif

// main program for testing the IMU.

if (SILSIM == 1)

int mp_argc;
char mp_argv;
int main(int argc, char
argv)
{
// keep these values available for later
mp_argc = argc;
mp_argv = argv;

else

int main(void)
{
mcu_init();

endif

if (USE_TELELOG == 1)

log_init();

endif

if (USE_USB == 1)

preflight();

endif

udb_init();
dcm_init();

if (USE_CONFIGFILE == 1)

init_config();

endif

init_servoPrepare();
init_states();
init_behavior();
init_serial();

udb_run();
// This never returns.

return 0;

}

Thanks for any help,

John

Comments

  • Some of the header files are conditional compiled (thats what all the #ifs are). Some of the functions that are declared in those header files are also conditional compiled in the main (this makes sense, since you can't access those functions if they are not compiled).

    Also the main is different depending on the SIMSIL flag...

    None of the functions (with the exception of one of the versions of main) takes variables, nor do they seem to return any. Also looks like it is using some globals to pass info around (mp_argc and mp_argv are in file scope)...

    hope that helps?

  • Sorry, I don

    t have a clue.
    Normally I would prototype a new function above (outside) the main, write the function itself outside the main, and get the result(s) in the main(); 
    In my case, all the functions are on seperate source- , and header files, I didn
    t see any prototypes, and hitting the compile button, it compiles all right, resulting in a functioning hex file.
    There
    s some basics about embeded Ide programming that I seem to lack knowledge about. 
    In my particular case where should I write what ? 
    When I declare a variable on top of my source file, that
    s called >sevomix.c< for example, the variable doesn
    t work as a global what I hoped it would.  
    I can´t just call and read it
    s value from within any function. And as I said, those source files (and headers too are just full of funcions and definitions and declerations.
    Where would I put a variable that I`d like to use as a global? Meaning that I can read it´s value anywhere at least inside the source file where it was declared on top?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories