views:

85

answers:

3

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,

  • Is there any way to mention the header from some command line arguments or something?
  • I just want to avoid re-compiling the source every time...
+2  A: 

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.

Jonathan Leffler
+1 Actually I use something like the above method. I actually do not edit the source code even now, I only change the project setting.
Alphaneo
+1  A: 

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?

qrdl
Eventually I am thinking of some perl or ruby script. But just wanted to know, if there is some other method.
Alphaneo
A: 

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.

Alphaneo