This makes no sense ... 'function' was not declared in this scope

At the top of the sketch, I define a few things.

#define no_error 1
#define error_occurred 2
#define error_cleared 3

because English is easier to understand (and remember) than numbers.

The following snippet of code inside

void loop()

fails to compile, with the annoying 'send_EMail' was not declared in this scope error.

if (!digitalRead(BilgePump) && !BilgePumpStatus) {
BilgePumpStatus=1;
send_EMail(error_occurred);
}
else if (digitalRead(BilgePump) && BilgePumpStatus) {
BilgePumpStatus=0;
send_Email(error_cleared);
}
else ...

However, if I comment out the first call to send_Email

if (!digitalRead(BilgePump) && !BilgePumpStatus) {
BilgePumpStatus=1;
// send_EMail(error_occurred);
}
else if (digitalRead(BilgePump) && BilgePumpStatus) {
BilgePumpStatus=0;
send_Email(error_cleared);
}
else ...

things compile fine! So it doesn't like the function call in the IF block, but is fine with it in the ELSE IF block.

One more option. If I change the value sent to the send_Email function,

if (!digitalRead(BilgePump) && !BilgePumpStatus) {
BilgePumpStatus=1;
send_Email(error_cleared);
}
else if (digitalRead(BilgePump) && BilgePumpStatus) {
BilgePumpStatus=0;
send_Email(error_cleared);
}
else ...

it again compiles fine! I'm afraid I just don't get it.

The send_Email function is placed ahead of loop(), because function prototypes (automatic or manual) don't seem to work with the Arduino IDE.

IDE is version 1.8.9. (Tried upgrading to 1.8.10 and everything broke .. maybe 200 errors on the SAME code.)

Any thoughts appreciated.

Alan

alan-bc:
The following snippet of code inside

If you want to post snippets, head over to https://snippets-r-us.com/.

If you want the best possible help here, post a complete code that fails with the exact same compiler error message that you're seeing.

Finally, USE CODE TAGS.

send_EMail(error_occurred);
send_Email(error_cleared);

Fix the 200 errors...compilers rarely bark at you as a joke....
Something is wrong in the rest of the code we have not seen, possibly with #define
Weird compiler behavior can be caused by code optimization, dead branches being trimmed

To avoid #define mess, using enums avoids weird replacements enum errorStatus:byte {no_error=1, error_occurred, error_cleared};

when you get the error "was not defined in this scope". it doesn't always mean you didnt define something. most the time it means you are missing a bracket somewhere. a misplaced bracket can group a variable or fuction somewhere the compiler just cant see it.

so many times the compiler will flag the line where first sees you mention the variable or function instead of where the brackets are screwed up around the actual function.

Sincere thanks to all who replied.

I'm afraid I'm at a loss. Using ENUM didn't change anything, nor did replacing the #define value with an actual number. Pass a "3" to the send_Email function, it compiles fine, pass a "2" and it fails with the "function not declared" error.

Using the newest IDE, zillions of errors on exactly the same code. (I didn't try an older IDE, as I was getting frustrated. Plus, going backwards to fix something that surely seems like it should work is not exactly confidence inspiring.)

So, rather than trying to track down with my extremely limited skills what seems like a compiler bug .. and not being able to fix it even if I found it .. I took the "cowardly" way out. I have different (non-Arduino) hardware intended for my next project and I simply used that.

Of course, a different compiler was required but after some minor tweaks to the code (little more than search and replace) and some pin definition changes, this one liked my code. Problem solved.

Thanks again.

So, rather than trying to track down with my extremely limited skills what seems like a compiler bug

What ever it is it is not a compiler bug.

If you don't want to post your code then say so. It is extremely frustrating that you have made such a simple error but won't let us have a chance at spotting it.

LOL @arduino_new captured it I believe.. and I failed to catch it up.

function names are case sensitive and in the buggy version you wrote this
send_E[b][color=red]M[/color][/b]ail(int errorCode);
and the other as

send_E[b][color=green]m[/color][/b]ail(int errorCode);

whilst in the working version you did fix the spelling mistake or commented out the function name...

so you messed up (and we failed to see it), not the compiler and it was right telling you that function was not defined....

Your zillions of errors very likely come from poorly written code, you might have warnings about types and similar. Always worth looking at those and understanding the why.

alan-bc:
So, rather than trying to track down with my extremely limited skills what seems like a compiler bug ..

Seriously? It's a poor craftsman that blames his tools. Especially a craftsman with (admittedly) "extremely limited skills".

Tool chain bugs do happen, but it's the last thing I consider when having problems with either compilation or execution of my code. As the saying goes, "if I had a dollar for every" newbie who blamed the compiler for their own mistakes …….

J-M-L:
LOL @arduino_new captured it I believe.. and I failed to catch it up.

function names are case sensitive and in the buggy version you wrote this
send_E[b][color=red]M[/color][/b]ail(int errorCode);
and the other as

send_E[b][color=green]m[/color][/b]ail(int errorCode);

whilst in the working version you did fix the spelling mistake or commented out the function name...

so you messed up (and we failed to see it), not the compiler and it was right telling you that function was not defined....

Your zillions of errors very likely come from poorly written code, you might have warnings about types and similar. Always worth looking at those and understanding the why.

Sometimes it happens due to libraries to be not imported, or their versions are below, but mostly it's just a sintaxic error like this. A compiler say the function wasnt declarated says it wasnt declarated, he shouldn't blame the compiler for pointing an error, in my whole time developing software codes, I've never seen a compiler prevent your code to be complied due to a bug...

If in doubt, cut/copy the name that the compiler says it can't find directly from the error message, and paste that into the text search tool.

J-M-L:
LOL @arduino_new captured it I believe.. and I failed to catch it up.

so you messed up (and we failed to see it), not the compiler and it was right telling you that function was not defined....

Well I stand up as SERIOUSLY embarrassed, as I did not catch that, nor did I catch what arduino_new was trying to tell me.

I stared at his reply just as I stared at my code (for HOURS) and just didn't see it.

In all my troubleshooting, and I did a fair bit trying to understand what was going on, there was a lot of copy and paste and a lot of commenting in and out of duplicated lines. Obviously, every failure had an "e" in the function name and every success had an "E" and somehow I just never caught it. And I stared at it for HOURS.

Well, it's nice to know it's not a compiler bug, and I agree, they're pretty rare (although by no means unheard of, particularly for GCC). But at some point, Sherlock Holmes starts to edge into consciousness ...

"When you have eliminated the impossible, whatever remains, however improbable, must be the truth"

Once you’re more ex perienced, you’ll type names automatically - using your own preference for capitalisation.
CamelCase, Hungarian notation etc...
You’ll find your groove, but be consistent!

To be honest I did not see it as well

the way I found it out was to write a simple program to show all was working and I copy pasted your broken code - without seeing it - and tried to compile and was stunned as well that it did not work.

So I looked up the error message and first started to ask myself would this function name cause some bug and tried to do a find/replace and then - bingo one of call was not replaced and that was my facepalm moment!

Did you not spot the large red M and small green m? I thought they stood out quite clearly. :wink:

Well I’m the one who highlighted that because I failed to see it in @arduino_new post

Yes it was some sort of a joke hence the :wink:

Ah - missed it sorry :slight_smile: