Thread: C Preprocessor Macro Question

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    C Preprocessor Macro Question

    Hi everyone,

    I'm trying to put together a c preprocessor macro that will conditionally compiler in/out code based upon a product release date and a feature release date. For instance, I'd like to conditionally compile out a feature that will be present in 2013 products from all products to be released in 2012.

    I'd like something that works like so:
    Code:
    if((product_release_date - feature_release_date) >= 0)
    {
        /* Include this code section in the build */
    }
    Basically I'm working on a code set that spans products from 2012 through 2015 and developing features that will be released in the coming years as the hardware makes it to production, but I don't want my prototype future feature code to get into products that will be released before the feature is read. I want to be able to code it and debug it now using the products it will be in but keep it out of the products it won't be in, and all products are coming out of the same evolving code base.

    Any ideas?

    Thanks,

    Matt

  2. #2
    Registered User
    Join Date
    Sep 2011
    Posts
    52
    Use #ifdef your_name than place your code, end with #endif.
    When your_name does not exist, the code will not get compiled in .o file. When it does exist, the code will be compiled in the product. I hope I've answered your question with this.

    Kind regards,

    Libpgeak

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
    #define ProductionYear 2011
    
    
    #if ProductionYear > 2013
    
    // year dependent extra code here
    
    #endif

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,213
    Wow - you're writing code now for 2015

    It would be interesting to see how much of your code today is still around in 4 years time. It might make you think whether any of it was worth writing to begin with.

    Most people seem to give up predicting the future of hardware and software capabiliites and requirements at 6 months.

    Personally, I think you should be spending all your time on making sure the next delivery (and hence the next payday) is as good as possible, rather than spending vast amounts of time on code for the dim and distant future.

    Write each idea for future years on a post-it note, and stick it to a whiteboard with colums for each quarter (in 2012) and each year for 2013-15. Takes a few minutes for each one (rather than hours or days spent mucking about with the code). Plus, it's
    a) easier to move them around
    b) you can keep a nice bin of all the ideas which didn't make it, and therefore you can see how much time you saved by NOT coding a feature that got binned before it was ever needed.

    Do a web search for "agile" development - because what you've suggested is the very antithesis of it.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Macro question
    By Mole42 in forum C++ Programming
    Replies: 4
    Last Post: 01-14-2011, 04:41 PM
  2. Preprocessor question
    By fraujansen in forum C++ Programming
    Replies: 0
    Last Post: 12-20-2010, 02:00 PM
  3. Macro/globals question
    By newlearner in forum C Programming
    Replies: 9
    Last Post: 07-18-2009, 02:53 AM
  4. Macro question
    By caduardo21 in forum C Programming
    Replies: 1
    Last Post: 06-26-2005, 01:13 PM
  5. _T Macro Question
    By mrafcho001 in forum Windows Programming
    Replies: 9
    Last Post: 06-11-2005, 09:00 AM