Connecting Tech Pros Worldwide Help | Site Map

Conditional compilation based on hardware info

ashok.anbalan@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
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

Martin Gieseking
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Conditional compilation based on hardware info


ashok.anbalan@gmail.com wrote in news:1117697469.098273.118760
@g44g2000cwa.googlegroups.com:
[color=blue]
> 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.[/color]


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
Andre Kostur
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Conditional compilation based on hardware info


ashok.anbalan@gmail.com wrote in news:1117697469.098273.118760
@g44g2000cwa.googlegroups.com:
[color=blue]
> 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.[/color]

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?

ben
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Conditional compilation based on hardware info


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
[color=blue]
> You want to compile a piece of code conditionally dependant on the[/color]
hardware[color=blue]
> configuration of the _compiling_ machine? What would happen if you take
> your executable and run it on a different machine?
>[/color]


Andre Kostur
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Conditional compilation based on hardware info


"ben" <benhongh@hotmail.com> wrote in news:429f212c$0$23801$afc38c87
@news.optusnet.com.au:
[color=blue][color=green]
>> You want to compile a piece of code conditionally dependant on the[/color]
> hardware[color=green]
>> configuration of the _compiling_ machine? What would happen if you take
>> your executable and run it on a different machine?[/color]
> The OP might be working on an operating system or device driver. It is
> perfectly reasonable to write machine dependent code in these cases.[/color]

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.
Sean Connery
Guest
 
Posts: n/a
#6: Jul 23 '05

re: Conditional compilation based on hardware info


Andre Kostur wrote:[color=blue]
> "ben" <benhongh@hotmail.com> wrote in news:429f212c$0$23801$afc38c87
> @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.[/color]

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

Closed Thread