Arduino IDE regular tab names vs TabName.h, with #include "TabName.h"

Greetings;

I wasn't quite sure, whether to post this in General Guidance or Programming.

Here goes:

As this project grew in size and I'm growing more comfortable with the IDE and C in general, I started using Tabs to make things easier for me. I don't yet feel comfortable enough with classes (as someone in the forum kindly pointed out).

I initially started with regular tab names, then started adding numerals in front, to have a fixed compile sequence.
Then, after having read somewhere, I started using TabName.h, with a #include "TabName.h" in the main program Tab.

These two notations seem to behave differently, and I opted to use the x.h as the norm and was trying to migrate the regular tabs to TabName.h.

Not so fast Grasshopper, said the IDE.

When I tried to move the TFT tab, it says that the instance of tft is not defined...
When I tried to move the GetUtpTime, it says that Udp is now called EthernetUdp
When I tried .... etc...

I'm making sure I define all the global variables on the main page, call instances on the main page, essentially only keep the functions on the other TABS.

I tried putting numerals in front, to force a compile sequence, to no avail...

Can someone please enlighten me on the topic, and maybe point me in the direction of a document?

As mentioned before, I don't yet feel comfortable with classes.

the #include's are // at the beginning of the main code, and the tab names are temporarily back to normal names, without the .h extension.

Cheers

Pump_Room_Server_functions.zip (11.2 KB)

A *.h file is not for functions or variables. It never has been and it never will, not even in the Arduino IDE. Well, it is the 'c' and 'c++' language, so there are execptions :wink: However, you should not put your functions and variables in a *.h file.

When you create a tab without file extension, then it becomes a *.ino file. That is some kind of addition to the main *.ino file.
You can also put functions in a *.c or *.cpp file. For example a seperate part of code or code copied from a library.

The #include is often done in the main *.ino file (the most left tab).
Sometimes a seperate part of code is in a *.cpp file and it needs its own *.h file, then it can be possible to put the include only in that *.cpp file.

Thanks Koepel;

So, if I understand you correctly, I should abandon the TabName.h approach and instead use TabName without extensions.

If I understand correctly, they will compile in alphabetical order following the main sketch, appended one after the other.

Will give that a try.

Cheers

I'll move this talk to the programming section, after running into problems with the suggested approach...

It's okay, you don't have to move this thread.

The Arduino preprocessor makes function prototypes and combines all *.ino files into a single *.cpp file and presents that to the compiler.

The Arduino preprocessor is improved and changed. I had to re-organize my #include's a while ago. That can happen. The 'c' and 'c++' language is strict and well defined, but what the Arduino preprocessor does is not always strict.
Sometimes you have to make a workaround, when the Arduino preprocessor fails.

I prefer to put my global variables in the main *.ino file. Even if that is a lot. It keeps me out of trouble :wink:

@trilife's new topic where the discussion is continued:
https://forum.arduino.cc/index.php?topic=686606