redefine or `alias' global variable names in setup?

Here's the sit'...
I've developed a universal sensor transmitting platform.
It's just a 328 with an on-board transmitter - and a unique placement of header pins. There is no limit to the type of daughter boards' (you guys call them shields') that can be plugged in. ( I just lied - each board has a unique ID' resistor - the discernable value difference would be a limit. :slight_smile: )

The over-view...
The first thing in setup is a look to see what board is plugged in. From there is goes thru a switch-case section where variables and constants are defined as appropriate for that particular board. Those constants and variables are used by subroutines in the `loop' that are also switch-case selected.
There can be over a dozen predefined board-specific subroutines - each with very different app-specific variable names chosen to make sense when reading the code. One board may need only a couple of variables and constants, another may need 10 of each.

The issue is...
It's wasteful ( and very messy-looking) to define all things for all possible boards globally - esp. considering that the exact function of each board is also in a state of flux. I'd really like to be able define constants and variables with meaningful names in each CASE section during setup. That way, when I need to update the LOOP' code for a particular board - the variable and constant names will make sense. I could globally define generic names like b_var1, b_var2, i_var1, i_var2, f_var1, f_var2, pin_PD0, pin_PD1, etc., but then I'd like to somehow get 'P_Temperature' = pin_PC0' - or RhSlope' = `f_var2', but after I know what board is installed.

Any ideas? I'm running into `That's not allowed.' a lot.

You could use either pointers, which might waste a lot of RAM, or just use defines:

#define TEMPERATURE var1

A good example is the gcc-avr code itself. Depending upon the chip that is being compiled for, various different variables and constants get defined. Excellent example on how to do what you want in a way that has been well thought out for consequence.

The Arduino IDE code also handles these same issues and is another example; however, in my opinion its methods have not been as well thought out.

Except he wants to change the names not the values.

BitHead may want to consider a C union, or perhaps even a C struct containing multiple unions.

KeithRB:
Except he wants to change the names not the values.

There are variable names that are changed/redefined depending upon which chip is defined for compiling. For instance PORTC is not defined for the ATMEGA328, but is for the ATMEGA1284.

I may be wrong, but it didn't sound like he was attempting to redefine any existing global variable names, just the ones he has created for his project; however, it is certainly possible to redefine existing ones using the same mechanisms outlined in both examples I provided.

Something like this;

// The following addresses a problem in version 1.0.5 and earlier of the Arduino IDE
// that prevents randomSeed from working properly.
// https://github.com/arduino/Arduino/issues/575
#define randomSeed(s) srandom(s)

which I used in my playground code for providing a true random seed since there is a problem with the way the default Arduino IDE defines the randomSeed(s) function.

Are you talking about options that are exercised at compile time (i.e. the programmer know what daughter boards are in use) or at run time (i.e. the program must be able to deal with whatever daughter board it finds.

The whole Arduino system is built around many compile time options which are triggered by the board you select. If you look at some of the Arduino code you will see many many lines of #defines for all the different boards.

If you need to write a generic program without knowing which daughter boards will be used I can't see any alternative to allowing for every possibility. You could, perhaps, have different functions that are called in setup() depending on what board is connected, but I'm not sure that could serve the purpose you are describing. In a compiled programming system all the references to variables are set at compile time.

...R

I would define a class for each board and then instance an object of the appropriate class once the board has been detected.

Oh crap - the session timed out and I lost all my carefully crafted `Thank You's , further explanations and possible alternative solutions.
I'm already late to leave - so , Thanks, it's run-time thing and I'll look into that.