Project

General

Profile

Resolved: Newbie question

Added by JohnO over 4 years ago

Using the Arduino IDE, the difference between return true; and return false; I think is the same as return 1; for true and return 0; for false. If the called routine reaches the end “}” without an explicit return would the calling routine see either of these conditions?


Replies (2)

RE: Newbie question - Added by cadwal over 4 years ago

JohnO wrote:
> Using the Arduino IDE, the difference between return true; and return false; I think is the same as return 1; for true and return 0; for false. If the called routine reaches the end “}” without an explicit return would the calling routine see either of these conditions?

If the function has a return type of int, what return false or return true does depends on compiling as C or C++, type conversions etc. In some cases, false is 0 and true really converts to 1, but historically false was 0 and true everything else. (if with a numeric argument…).

Not having a return statement should result in a warning and not executing one normally causes an undefined return value (if you know the ABI you can usually figure out what will happen in each case) except for the main function (in some standards at least) where it is 0.

RE: Newbie question - Added by JohnO over 4 years ago

Cheers cadwal have a great weekend.

    (1-2/2)