Alphaneo
Alphaneo

Reputation: 12539

Header file-name as argument

Objective: I have a list of header files (about 50 of them), And each header-file has few arrays with constant elements. I need to write a program to count the elements of the array. And create some other form of output (which will be used by the hardware group).

My solution: I included all the 50 odd files and wrote an application. And then I dumped all the elements of the array into the specified format.

My environment: Visual Studio V6, Windows XP

My problem: Each time there is a new set of Header files, I am now changing the VC++ project settings to point to the new set of header files, and then rebuild.

My question:

A bit in-sane though,

Upvotes: 0

Views: 275

Answers (3)

qrdl
qrdl

Reputation: 34967

Headers are included at compile time so there is no means to change/add headers at runtime.

Why don't you just write a short and simple Perl script that will parse headers and count number of array items?

Upvotes: 1

Alphaneo
Alphaneo

Reputation: 12539

Actually I arrived at a solution that works.

  • Step-1: The header file-names would be predefined
  • Step-2: Headers (set) with different parameter values will be placed in different folders
  • Step-3: While compiling, point to the path with the appropriate headers

The solution is not what I wanted, but still, it was best I could figure out.

Upvotes: 0

Jonathan Leffler
Jonathan Leffler

Reputation: 753685

Standard C and C++ allow you to use a macro in:

#include SOME_MACRO_HERE

The expanded value of SOME_MACRO_HERE must look correct for a #include directive.

Hence, in principle, you could use the MSVC equivalent of:

cc -DSOME_MACRO_HERE='<actualheader.h>' sourcefile.c

Or:

cc -DSOME_MACRO_HERE='"actualheader.h"' sourcefile.c

This seems to provide you with an answer to your first bullet-question.

I'm not convinced you can avoid recompilation - you can (perhaps) avoid editing, though.

Upvotes: 2

Related Questions