Connecting Tech Pros Worldwide Help | Site Map

Conditional compilation based on hardware info

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 04:58 AM
ashok.anbalan@gmail.com
Guest
 
Posts: n/a
Default Conditional compilation based on hardware info

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, 04:59 AM
Martin Gieseking
Guest
 
Posts: n/a
Default 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, 04:59 AM
Andre Kostur
Guest
 
Posts: n/a
Default 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, 04:59 AM
ben
Guest
 
Posts: n/a
Default 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, 04:59 AM
Andre Kostur
Guest
 
Posts: n/a
Default 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, 05:01 AM
Sean Connery
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.