C questions

Greetings,

First, I am really excited to get into this micro! Looks like a lot of fun. I'm new, and I hope I don't violate some forum rule in this post!

I had some questions while I struggle with continuing to learn C and then starting arduino.

  1. variable declarations -- I am confused on where the arduino ide would put my "mycount" variable as I normally would code it. I guess my main concern is that it is not visible to functions, ie, it is Automatic. See code below.

  2. What about function prototypes. Does this work in arduino ide? (I read how arduino build process scans and builds function prototypes but I would rather do it as below.

 int myfunc(void);  // is this ok??

int main(void)
{
    int mycount = 500; // this variable is not accessible inside functions, right??

// code here
mycount++;
myfunc();

//more code etc. 

return 0;
}

int myfunc(void)
{
   int myfuncvar;  // this variable is not visible outside the function, right??
   // more code here. 
return 0;
}

From just reading the examples, I am impressed :slight_smile: how the arduino ide allows easy access to the AVR timers, etc. Normally, using these is much more technical.

I am looking forward using the arduino h/w and s/w.

Best Regards,
Steve.

The main() function is provided by the arduino environment. main() calles setup() once and loop() forever; you provide setup() and loop().

Variable scoping is the same - the language isn't C-like, it is C, specifically avr-gcc (I guess I should really say it's C++, using the g++ compiler).

The arduino IDE generates function prototypes for you, which on rare occasions causes confusion or problems.

-j

If you're really concerned about the auto-prototyping, you can always create extra tabs for straight .c or .cpp files in your sketch (click the right-facing arrow at the upper right of the IDE for the menu). Those files aren't modified at all by the build process.