Connecting Tech Pros Worldwide Help | Site Map

Conditional compilation based on hardware info

  #1  
Old July 23rd, 2005, 05:58 AM
ashok.anbalan@gmail.com
Guest
 
Posts: n/a
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

  #2  
Old July 23rd, 2005, 05:59 AM
Martin Gieseking
Guest
 
Posts: n/a

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
  #3  
Old July 23rd, 2005, 05:59 AM
Andre Kostur
Guest
 
Posts: n/a

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?

  #4  
Old July 23rd, 2005, 05:59 AM
ben
Guest
 
Posts: n/a

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]


  #5  
Old July 23rd, 2005, 05:59 AM
Andre Kostur
Guest
 
Posts: n/a

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.
  #6  
Old July 23rd, 2005, 06:01 AM
Sean Connery
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 14th, 2005 04:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM