Understanding a code

 

I am trying to understand the logic why it did not work on the first code, the below code is supposed to measure the number of pips between TP and SL

My question is why the name of the function and name of the double declaration in the body can not have the same name? specially that it make more sense for me ,  since diffTPSL has been declared as a double, and I diffTPSL to be the sum of a and b (TP , SL) and to return the value of diffTPSL , I dont understand why it did not compile

thanks for your help


 * FIRST CODE

extern int TP = 50;

extern int SL = 30; 



void OnStart()
  {
Alert (diffTPSL(TP,SL));

  }
//+------------------------------------------------------------------+
//Function Section
//---------------------------------------------------------------------

double diffTPSL (double a, double b)

{
diffTPSL = a + b;

return(diffTPSL);}



--------------------------------------------------------------------------


SECOND CODE:

extern int TP = 50;

extern int SL = 30; 







void OnStart()

  {

Alert (diffTPSL(TP,SL));



  }

//+------------------------------------------------------------------+

//Function Section

//---------------------------------------------------------------------



int diffTPSL (int a, int b)



{int difference;

difference = a + b;



return(difference);}





 
double diffTPSL (double a, double b)

{
diffTPSL = a + b;

return(diffTPSL);}

I don't think that it is a good idea to have a variable named the same as a function, but if you do use it you must declare it.

double diffTPSL (double a, double b)

{
double diffTPSL = a + b;

return(diffTPSL);}
You should have seen the error report when you tried to compile it.
 
Keith Watford:

I don't think that it is a good idea to have a variable named the same as a function, but if you do use it you must declare it.

thank you, but indulge me as I am trying to understand how the system read the code

double diffTPSL

So this will not be considered as declaration because it does not end with semicolon or because it has been followed by the brackets that include the elements and the curly brackets that include the body or all the previous?

it could be very primitive question but I know that the First code is wrong and I want to know the correct reason for being wrong

 
Michael:

it could be very primitive question but I know that the First code is wrong and I want to know the correct reason for being wrong

I already told you why.

 
Keith Watford:

I already told you why.

Thank you so much