NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Function Prototypes

March 02, 2011
by snagle
snagle's Avatar

I have completed the LED Array project and everything is working as it should; however now I am trying to add some functionality to this application and it requires the addition of some new functions within the "ledarray.c" source file. I may be missing something, but for the life of me I can't find where the function calls are declared (i.e. where are the function prototypes?). I need to add some declarations for the new functions I have created, but I have looked through all of the header files (.h files) and I can't even find where the original functions are declared. Could someone please point me in the right direction. Like I said, I must be missing something. Thanks for the help.

March 03, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi snagle,

You can just add your new functions directly to ledarray.c. You only need to create .h files when you are going to be linking external files against your .c file. Since ledarray.c contains the main() method you don't need to declare the methods in any outside file.

Humberto

March 03, 2011
by snagle
snagle's Avatar

Humberto,

Thanks allot for your help. If I understand you correctly, you are saying that it is unnecessary to declare functions within the file where "main()" exits (i.e. no need for a function prototype). Any new functions can just be written without a preceding declaration and they will just get defined implicity by the compiler?

Thanks again for the help.

Snagle

March 04, 2011
by Rick_S
Rick_S's Avatar

The only time you would have to declare them is if you place the function below where it's called for example.

void myfunct(){
    it's code
}

int main(){
  do this...
  myfunct();
}

Would work without declaring however,

int main(){
  do this...
  myfunct();
}

void myfunct(){
    it's code
}

Would not without declaring before main. At least that's my experience. :)

YMMV

Rick

Post a Reply

Please log in to post a reply.

Did you know that the microcontroller's crystal oscillator can be used to keep accurate time? Learn more...