Ghost "unterminated #else"

hi,
I have a quite long program with many tabs.
It does not compile and stops with

exit status 1
unterminated #else

The problem is, that I have absolutely no #else directive in my program!

At least the find routine (searching for #else with "search all tabs" on) does not find one.

What would you do in such a case?

What would you do in such a case?

Where does the error message say the problem is ?

Please post the full error message

Yes knowing where it is would be big help.
Can you post the full compiler output so we see what is happening?

I would guess that there is a nested comment somewhere.
i.e. perhaps a stray /* with no terminating */

Or a macro that not being passed proper parameters.

It is possible that a nested comment begins in one file or module and is affecting a conditional in another.

Once you know which file has the error, (I'm guessing that it is in a header file), then start to look at what code precedes the include for that header file.

Worst case you start using #if 0 to block out sections of your code until you can isolate the issue.

--- bill

what version of the IDE are you using? is it set up to show verbose error messages?

I find that when code elements I did not write crash the IDE, what failed was the code in a library, usually because I did not pass a parameter correctly

Go through each tab of your code and auto-format the code, then make sure the last few lines in each tab line up with the left side of the window properly. You may have omitted a closing bracket that is getting compiled immediately before including a library file in another tab.

Also scroll up in the error window of the IDE and look for the first few errors or warnings, often an initial error will result in numerous misleading error messages in the remainder of the code that are only an error because the initial erroneous code did not get compiled properly.

UKHeliBob:
Where does the error message say the problem is ?

Please post the full error message

That was the full error message:

exit status 1
unterminated #else

I had not marked place indicated.

Meanwhile I have copied tab by tab everything in a new project and got it compiling...

???

bperrybap:
i.e. perhaps a stray /* with no terminating */

--- bill

I am using /* strays potentially terminating with */ on next tabs.
Normally it works well.

But find works also within comments.

RIN67630:
That was the full error message:

exit status 1
unterminated #else

The error messages (all of them) are in the text box below your sketch. Each message will report the file name, line number, and character within the line where the error/warning was detected. When the error occurs, copy all of the text from the box containing the errors and paste it into a reply here.

RIN67630:
I am using /* strays potentially terminating with */ on next tabs.
Normally it works well.

But find works also within comments.

I do not understand what you are saying.
Are you saying that you start a comment in the code one tab and then terminate in the code of another?
If so, I would highly discourage doing this as it can cause issues.

I would also highly discourage the use of /* and / comment delimiters to block out or "comment" out code.
Use #if 0 and #endif to block out code sections.
It is just as simple, and not subject to any type of comment nesting issues.
i.e. #if 0 always works, but using /
can fail depending on the code being commented out.

The IDE smashes together all the code in its "tabs" that are .ino files to form a single .ino file before converting that to a .ccp file to send to the compiler.
I don't think that there is a guarantee as to the order that they will be placed in the .cpp file; however they seem to be placed in the file in alphabetical order. This can be a different order than the tabs.
For example, you can rename a tab. That will change the name of the tab and the name of the corresponding file associated with the tab but will not re-order the tabs in the IDE. (until you restart the IDE on that project)
So when you do a compile the IDE will pull in the files in alphabetical order into the .cpp file for compiling, which can be different than the tab order.

Also, if you use a mix of upper an lower case letters for the starting file/tab name, the order of the tabs can be different than the order that the files are smashed together.
This is because the OS and IDE may not have the same notion of how "alphabetical" sorting is done.
Not sure what happens on Windows, but on linux, it appears that the IDE use simple ASCII sort order for grabbing files to put into the .cpp file to compile but uses a different order (perhaps the LOCALE order rules) to display the tabs when the IDE is opened on the project.
i.e. upper case letters are treated the same as lower case when pulling in the files into the .cpp file but are not when displaying the tabs in the IDE.

So even the IDE does not seem to be consistent with itself.

Moral of the story, never depend on the order of the tabs being shown in the IDE.

--- bill

put the cursor on the bottom of the green band below the text window, where the green meets the black, and pull up. if you have turned on verbose error messages, there should be many orange messages you could not see under the text window

if there are no messages:

File: Preferences: check Show verbose output during: ( compiling box )

There is a handy button in the lower right hand corner of the IDE labelled "Copy error messages" which copies the entire error message, so you can easily paste it here between code tags.

RIN67630:
I am using /* strays potentially terminating with */ on next tabs.
Normally it works well.

This is absolutely likely to be your problem. You have no control on the sequence of the tabs being read by the compiler.

Each tab should be a complete function or group of functions. If you have a comment at the end of the tab, close it in that tab.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.