Can I #endef something defined in a libray and then re- #define it?

Hi,

An included IR receive library defines the receive buffer size as:

#define RECV_BUF_LENGTH 400

Is it possible to do the following in my sketch?


 #undef RECV_BUF_LENGTH
 #define  RECV_BUF_LENGTH 200

What is the order that files are read by compiler?
Will the value of 200 take effect through the compilation process or will it just mess things up?

you would have to redefine it after after every #include of the header file which defines it

Also consider that at the point where you redefine it the compiler might have already read the definition you don't want and acted on it. So, for example, it might have created RECV_BUFF with a length of 400 before it finds your re-definition.

One solution, and I don't know if this is the the best, is if you want to modify a library in any way then make a copy of it, change its name to something that suggests you've edited it and use the edited copy. Then you can do what you like with it without making a mess of the original.

Just one clarification - when creating your copy of the library to make changes, be sure to remove the original library from the libraries directory, otherwise the compiler will try to use both. Renaming the folder will not help here, the library must be physically removed from the directory

if you want to modify a library in any way then make a copy of it, change its name to something that suggests you've edited it and use the edited copy. Then you can do what you like with it without making a mess of the original.

Modifying the library was of course an option I have already tried and works fine.
However, I wouldn't like to follow this route since libraries get updated and I would have to remember to make the same modification every time a new version is available.

This is why I would prefer to add something in my own code instead and leave the library unchanged.

This won't work as your code is already too late to redefinition of the buffer. The explanation see at the first part of post #3

Do you reupload all your sketches every time library gets updated?

Do you reupload all your sketches every time library gets updated?

I might. But i also do upload the sane sketch to different devices. eg mqltiple sensor modules

Understood!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.