Conditional compilation based on hardware info

Discussion in 'C++' started by ashok.anbalan, Jun 2, 2005.

  1. Hi,

    I am working with a VC++ based tool that does hardware reads & writes
    besides some other stuff.

    I want to conditionally compile a piece of code based on the value of a
    field in a register i.e. only if the bit in the register is set I want
    to go ahead & compile the piece of code else it is left untouched.

    Basically, this has to happen at the pre-processor stage.

    I am unable to use the simple if-else since upon doing that the tool
    crashes.

    Any hints/directions?

    Thanks,
    Ashok
     
    ashok.anbalan, Jun 2, 2005
    #1
    1. Advertisements

  2. wrote in @g44g2000cwa.googlegroups.com:

    Your compiler should support defining preprocessor variables/macros via
    command line parameters (e.g. -Dfoo=bar). So write a short helper program
    that reads out the register and provides the necessary information. In your
    makefile you can execute the helper program and use its information to set
    a corresponding preprocessor variable by command line parameter.

    Martin
     
    Martin Gieseking, Jun 2, 2005
    #2
    1. Advertisements

  3. ashok.anbalan

    Andre Kostur Guest

    wrote in @g44g2000cwa.googlegroups.com:
    You want to compile a piece of code conditionally dependant on the hardware
    configuration of the _compiling_ machine? What would happen if you take
    your executable and run it on a different machine?
     
    Andre Kostur, Jun 2, 2005
    #3
  4. ashok.anbalan

    ben Guest

    The OP might be working on an operating system or device driver. It is
    perfectly reasonable to write machine dependent code in these cases.

    ben
     
    ben, Jun 2, 2005
    #4
  5. ashok.anbalan

    Andre Kostur Guest

    Machine-dependant code isn't my question. The OP wanted to conditionally
    _compile_ certain code (he mentioned preprocessor-time), dependant on the
    presence of certain hardware in the _compiling_ machine, not necessarily
    the _target_ machine. This seems odd that the conditional compilation
    would depend on the hardware of the machine that it's being compiled on,
    and not the machine it's intended to be run on.
     
    Andre Kostur, Jun 2, 2005
    #5
  6. ashok.anbalan

    Sean Connery Guest

    I would be supremely interested in why the OP wants this.
     
    Sean Connery, Jun 3, 2005
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.