dj0tt / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Boolean function versus boolean variable #1077

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a function "boolean myfunction() {}"
2. Call the function in the program but do not include the brackets. For 
example "if (myfunction) {}"

What is the expected output? What do you see instead?

1. The compiler accepts this routine but even though there is no boolean 
variable "myfunction" declared.

2. When you run the program nothing happens as it does not call the function or 
worry that myfunction variable was not declared.

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

Arduino version 1.01. This happens on any Arduino board.

Please provide any additional information below.

Original issue reported on code.google.com by colin.ge...@gmail.com on 19 Oct 2012 at 10:53

GoogleCodeExporter commented 9 years ago
This is a property of the C language.  "myfunction" by itself (no parenthesis) 
is interpreted as a pointer to the function, rather than a call to the 
function, so "if (myfunction)" is a valid (if rather useless) statement, 
similar to "if (0x1234)"

Original comment by wes...@gmail.com on 20 Oct 2012 at 2:15