are functino prototypes needed?

Hello all. I am working on some code. It uses the wonderful arduino IR receive library.

My specific issue is with the function i have defined at the bottom " getKeyFromIRCode "

the error i get is that it can not be used as a function.

Can somebody please explain to my why this is? I Didnt think that arduino needed prototypes declared (i have other sketched where they are not declared and the aux functions are written after / below the loop() function)

thanks for your time!

// INCLUDES

#include <IRremote.h>







// VARIABLE SETUP

int RECV_PIN = 8;

IRrecv irrecv(RECV_PIN);

decode_results results;





// set up possible commands / result codes

String bNames[] = {"ON" , "OFF"};

String bCodes[] = {"F740BF" , "F7C03F"};





// FUNCTION PROTOTYPES

int getKeyFromIRCode(results.value);





// FURTHER SETUP

void setup()

{

  Serial.begin(9600);

  irrecv.enableIRIn(); // Start the receiver

  Serial.println("we're alive!");

}



void loop() {

  int tmp = 0;

  if (irrecv.decode(&results)) {

    Serial.println("Here Comes The Native Result");

    Serial.println(results.value);

    Serial.println("There Was The Native Result");

    delay(250);

   tmp =  getKeyFromIRCode(results.value);

    irrecv.resume(); // Receive the next value

  }

}













// AUX FUNCTIONS

int getKeyFromIRCode(results.value){

  

    Serial.print("was passed");

    Serial.println(ircode);

    Serial.println("Above is the WasPassed");

    return 3;      // jsut to get past the compiler

}
int getKeyFromIRCode(results.value);

That's not a prototype.

The prototype needs a type, like:

int getKeyFromIRCode(int);

The actual function definition needs a type AND an identifier:

int getKeyFromIRCode(int value);

It should be a simple identifier (not "foo.bar", just "foo"); unless there is C++ magic there that I'm not familiar with, being mainly a C programmer.

To answer your topic question, it depends. Function prototypes are required, if the function is not to be defined before it is used, but the Arduino IDE generates them for you, in most cases.

There are a few cases where it fails to generate a prototype. One case where it fails is if the function uses reference arguments.

That is not the case in you code though, so the Arduino IDE will define the prototype for you, when you define/implement the function correctly.

Thankyou all. I've fixed the error in my code. I had forgotten that you only need to specify the datatype when declaring the prototype.

and i was not aware under which conditions you needed to declare a prototype. Thanks all.