Thread: Trying to redefine library #defines

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    Trying to redefine library #defines

    My project use a series of libraries, some of which I need to tamper with their preprocessor constants.

    PDcurses (a portable curses implementation), for instance, has a some keyboard #defines that I need to alter since not all of them match my system's. Another one is boost::filesystem which uses <errno> for its exception handling. Unfortunately MinGW implementation of errno.h falls short and many of its preprocessor constants don't match my system's error codes.

    This is new grounds for me and I'm unsure how I should implement these changes in a portable way.

    One possibility I'm thinking is to make my own headers, include these libraries and then use a trio of #ifdef, #undef and #define for those preprocessor constants that I need changed. My app then includes these headers instead of the original ones.

    Is this desirable? Not? Or is there a better approach?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There is no portable way of messing with 3rd party libraries, and even less so when messing with system libraries (errno).

    But header overriding by placing your own equally named header earlier in the include path is not a bad way of doing it, especially since it means you don't have to modify the current code.

    However, there might be problems if through a library-internal include path the unmodified header gets included. Depending on how the compiler looks up include files and how the library includes them, it could happen.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Hmm... maybe perhaps I'm better then defining my own constants and work with them instead of the ones used in these libraries? Instead of trying to redefine those preprocessor constants, I simply ignore them and create my own (with the advantage I can create const constants instead of #define...

    You think this possibly a better approach?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you're creating your own API, then creating your own constants as well seems like a good idea. It's certainly the most maintainable approach.

    If you want certain of your constants to directly equate to other library constants, then you're free to make that association inside your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Thanks. So it will be.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 01:28 PM