Conditional compilation based on hardware info

A

ashok.anbalan

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
 
M

Martin Gieseking

(e-mail address removed) wrote in @g44g2000cwa.googlegroups.com:
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.


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
 
A

Andre Kostur

(e-mail address removed) wrote in @g44g2000cwa.googlegroups.com:
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.

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?
 
B

ben

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
 
A

Andre Kostur

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

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.
 
S

Sean Connery

Andre said:
@news.optusnet.com.au:

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.

I would be supremely interested in why the OP wants this.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top