How to declare arrays in another (not main) tab?

adrian_h: Sorry? Who's guessing? Not me, that's for sure.

Well, that's how it seems to me. You seem to be speculating about the correct way to declare and define your data, and talking about adding and removing const and extern declarations. You've already narrowed the solution down to two alternatives, neither of which are right. If this isn't guesswork I don't know what it is.

There's no need to guess. There is an overwhelming quantity of examples of this on the internet, it's the bread and butter of C++ programming. Putting your definitions in a .h file is not the right way to do it. Replicating the declarations in the code that is trying to use the data is not the way to do it. The right way to do it is to put your definitions in a .cpp file and the corresponding external declarations in a .h file.

PeterH:
Well, that’s how it seems to me. You seem to be speculating about the correct way to declare and define your data, and talking about adding and removing const and extern declarations.
You’ve already narrowed the solution down to two alternatives, neither of which are right. If this isn’t guesswork I don’t know what it is.

There’s no need to guess. There is an overwhelming quantity of examples of this on the internet, it’s the bread and butter of C++ programming. Putting your definitions in a .h file is not the right way to do it. Replicating the declarations in the code that is trying to use the data is not the way to do it. The right way to do it is to put your definitions in a .cpp file and the corresponding external declarations in a .h file.

If you are a programmer, then you know that there are a myriad of ways to do any one thing. Yes, I stated only 2 and they work, but that is only for simplicity. There are quite a few ppl here who are not programmers, and I am trying to address to the lowest common denominator. Please remember that the Arduino platform is a simplified platform, with the ability to scale up as needed for more complex applications.

If you have better solutions, please bring them forward. This is a forum to help each other, not to talk down to people, say “No, your wrong” and leave it at that. I think you should readjust your attitude. And for the record, I’m not guessing.

Adrian

adrian_h: If you have better solutions, please bring them forward.

I've already said what the right solution is.

I appreciate that you're trying to help, but you're giving bad advice, presumably because you don't know better. Creating a program consisting of multiple source files is something that is done routinely in 'C'/C++ and there is no need for you to speculate about whether you need 'extern' and/or 'const' and whether your declarations and/or definitions should go in header or source files and so on.

Don't put your definitions in header files as you suggested - that will lead to duplicated symbol definitions as soon as you need to share data between modules. Don't put your declarations in the client code as you suggested - that will lead to duplication of the declarations which reduces maintainability and can introduce some very nasty bugs.

The right way to do it is to put your definitions in a .c/.cpp file and the corresponding external declarations in a .h file. Any client code needing visibility of the declarations in a module can then simply include the appropriate header. The language and development tools have been designed around this simple scheme which works for programs from a handful of lines of code up to hundreds of millions of lines of code. The fact you can flout this convention and still get code to compile in simple situations doesn't mean it's a good idea and doesn't mean that you should be recommending that approach to novices asking for advice about how to do this.

If you don't know what declarations and definitions are or how these should be coded then look for examples. There countless examples in the internet and plenty of good examples in the Arduino runtime library itself.

PeterH:

adrian_h: If you have better solutions, please bring them forward.

I've already said what the right solution is.

What you have basically said is to go look it up to a person who is asking for help without making any suggestions as to where to get such information, except "the internet". Good job. :D

PeterH: I appreciate that you're trying to help, but you're giving bad advice, presumably because you don't know better. Creating a program consisting of multiple source files is something that is done routinely in 'C'/C++ and there is no need for you to speculate about whether you need 'extern' and/or 'const' and whether your declarations and/or definitions should go in header or source files and so on.

I do know better. If I were to use a real IDE and a project was worth the trouble, I would go on about how to use header files in general. This however is a small project not requiring this level of information. If the OP really needs it, s/he will ask.

PeterH: Don't put your definitions in header files as you suggested - that will lead to duplicated symbol definitions as soon as you need to share data between modules. Don't put your declarations in the client code as you suggested - that will lead to duplication of the declarations which reduces maintainability and can introduce some very nasty bugs.

Actually, no, it won't. You can put constants in a header file without that problem. This allows for compiler optimization and meta-template programming.

PeterH: The right way to do it is to put your definitions in a .c/.cpp file and the corresponding external declarations in a .h file. Any client code needing visibility of the declarations in a module can then simply include the appropriate header. The language and development tools have been designed around this simple scheme which works for programs from a handful of lines of code up to hundreds of millions of lines of code. The fact you can flout this convention and still get code to compile in simple situations doesn't mean it's a good idea and doesn't mean that you should be recommending that approach to novices asking for advice about how to do this.

If these were not constant, then yes, that IS the way to do it. This doesn't break things as you scale up when using C++.

PeterH: If you don't know what declarations and definitions are or how these should be coded then look for examples. There countless examples in the internet and plenty of good examples in the Arduino runtime library itself.

Countless, yes. However, you don't really state anything that is useful. No real direction except waving your hand and saying "go that way". To reiterate, my response is for SIMPLICITY. If the people here really want to get into it, they would read books like the ones listed here: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list, go for schooling in programming and ask more questions as they go along (which is the purpose of this forum).

Additional resources are: