0

I have a project in which basically i have to concatenate existing code. Each code comes with its own #defines. But defines are not touched by the compiler, but the preprocessor.

Each snippet of the program will exist in its own fucntion.

Is it possible to include the #defines of each program - now each function, inside this function (and visible only to this function's scope)?

The proper way to do it, would be to replace text reassignment from #define to typedef?

I understand typedef is originally for defining types. But can it be used here? Is there another alternative?

  • 1
    What are these macros used for? You can replace them with different things depending on what they are, but you may lose execution efficiency. – Majenko Jun 1 '17 at 18:03
  • The macros are used for text replacement. For example #define value 255 – user1584421 Jun 1 '17 at 18:05
  • Then you would use const variables. – Majenko Jun 1 '17 at 18:06
1
#define value 255

Can be replaced with

const int value = 255;
| improve this answer | |
1

It is possible to use "namespace { ... }" to create local defines for a *.cpp file.
In the Arduino IDE all *.ino files are combined in a single *.cpp file, therefor the "namespace" is not very useful.

When you create new tabs in the Arduino IDE and name them *.cpp, then you have different *.cpp files. Then you can use the "namespace" to create defines that are only valid for that *.cpp file.

More info: Hackaday: Using Modern C++ Techniques with Arduino

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.