This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Conditional compilation

Hi,

I am currently trying to get my code support two different type of LCD display, the only difference is the hardware level driver, so condional compilation directive has to be introduced.

#ifdef DISPLAY_1
void display_driver()
{
// do one thing
}
#else
void display_driver()
{
// do another thing
}
#endif

However I don't want change the directive in the code, I would like to do it in the IDE,
I guess it should be under project\option\C51, any one know how to do it ? Thanks in advance.

Daniel

Parents
  • The trouble with "parallel files" is that, if they are very similar

    If the files are very similar, I agree. Drivers for two different devices, on the other hand, aren't likely to have any similarities other than the names and parameters of the API.

    Often in such a case, you've discovered a natural interface in the design. The one file that originally seemed to be a single coherent module really has subcomponents. You can then factor the two parallel files into one common file, plus a few helper / utility functions that encapsulate the true differences. You'd have one common file with the common code and two auxiliary files, of which you link one.

    At some point, the changes are so minor or the granularity of the change so small that it's easier to do conditional compilation rather than refactor the code.

Reply
  • The trouble with "parallel files" is that, if they are very similar

    If the files are very similar, I agree. Drivers for two different devices, on the other hand, aren't likely to have any similarities other than the names and parameters of the API.

    Often in such a case, you've discovered a natural interface in the design. The one file that originally seemed to be a single coherent module really has subcomponents. You can then factor the two parallel files into one common file, plus a few helper / utility functions that encapsulate the true differences. You'd have one common file with the common code and two auxiliary files, of which you link one.

    At some point, the changes are so minor or the granularity of the change so small that it's easier to do conditional compilation rather than refactor the code.

Children
No data