| beakie (156) | |||||||
|
Basically... I want to create some variables which, unless specified at compile time, aren't included in the compile. I was thinking of doing it like this: 3 structs, each contains the variables I want to include/exclude. I then create a class which inherits from all 3 structs.
Essentially the same as: (right?)
If it is... ...(next bit)... ...is is appropriate to use macros like this?
I know this is gonna make a lot of people laugh/cringe, but it would achieve my goal, right? I won't have more than 1 instance of this in my code... and the compiled memory size/program size is FAR more important than tidy code/or blindly followed standards. This is for an MCU.... Is there a better way to do what I want? | |||||||
|
|
|||||||
| NwN (591) | |
|
Why don't you put those variables in an external file and only include the file in the compilation when you want to? Why you would do this seems weird to me - this is asking for compiler errors about "undefined variables" etc. Also, if your first example and your second are the same, as you indicate yourself, why would you opt for the longer and more obfuscated one? I'm not criticising, I'm too much of a beginner myself, just interested at why you are taking this route. All the best, NwN | |
|
|
|
| beakie (156) | ||||
I figure, including/excluding a header file with bits of code amounts to the same thing... dodgy code :-/ right? I would LIKE the source to be constant whether or not a #define flag is passed in. The inheritance isn't the point. I could declare 3 structs and put them all IN another struct... in fact, this would probably be a preferable structure... but I would still have to macro out the struct variables in the master struct.... just as dodgy :)
The problem with the second is that the code with contain more bytes than its going to need. This isn't an option.
:) | ||||
|
Last edited on
|
||||
| KRAkatau (121) | |||||
Why do you use preprocessor to cut out the inherited structures and not the variable declaration themselves?
Also if the variables are of the same type - then you can do the following:
This will have no redundancy as well and will depend on how you instantiate the template. This will allow you to concentrate all the ifdefs in one place - where this structure is used. | |||||
|
|
|||||
| beakie (156) | |||
I put them in structs because another struct, say masterstructB will have them all. this struct will be used off the mcu and having those extra few bytes makes no difference to a desktop based system.
they are not. the code above was written to ask my question only. there are lots of variables and a few functions spanning those child structs. ummmmm.... | |||
|
|
|||