Calling a subroutine doesn't work

Hello,
This drives me nuts - how come this example works when I uncomment commented lines, but fails to work when the lines are commented? Please help!

void setup ()     { pinMode (1, OUTPUT); }
void blink1()
{
  digitalWrite(1, HIGH);
  delay(1000);   
   digitalWrite(1, LOW);             
   delay(1000);    
}   
void loop ()
  {
  blink1;
/*digitalWrite(1, HIGH);
  delay(1000);   
   digitalWrite(1, LOW);             
   delay(1000); 
*/
  }

blink1;That's not calling a function, is it?

Hint: digitalWrite is a function, and that works, right?

It is supposed to call it, but doesn't . Can't figure out the reason.

OK, take another look.
digitalWrite is a function.
delay is a function.
pinMode is a function.

What do these have when you call them that blink1 does not?

It is supposed to call it

Not according to the language spec, it isn't.

What I mean is that this code below doesn't work. If I insert the same instructions from the blink1 subroutine into the loop, it works fine.

void setup ()     { pinMode (1, OUTPUT); }
void blink1()
{
  digitalWrite(1, HIGH);
  delay(1000);   
   digitalWrite(1, LOW);             
   delay(1000);    
}   
void loop ()
  {
  blink1;

  }

I understand what you're trying to do, but you're not calling blink1, but you are calling delay(), and pinMode() and digitalWrite (). (I left you three massive clues there )

Got you. Blink1(); Thought I was missing something very stupid. Thank you very much!

That's right.

The compiler doesn't complain, because there's nothing wrong with the code, just like this

void loop ()
{
  42;
  blink1();

}

AWOL:
That's right.

The compiler doesn't complain, because there's nothing wrong with the code, just like this

void loop ()

{
  42;
  blink1();

}

Is there any chance you could explain this further? Why is there nothing wrong with it? I can sort of understand why the constant isn't an error but what does the compiler think you are trying to do by writing the function name on its own?

I can sort of understand why the constant isn't an error but what does the compiler think you are trying to do by writing the function name on its own?

If you can understand why a numeric literal doesn't cause a problem I don't really see why you think a bare function pointer (hint) should cause a problem.

Getting and throwing away the address of the function.

KeithRB:
Getting and throwing away the address of the function.

...and evaluating it zero/non-zero (in theory)

I didn't know the name on its own is a pointer to the function. Thanks very much :slight_smile: