setting the pre-processor variable during execution time..

R

Ram

Hi,

I have some code in my header file like this:

#if defined(some #define variable)

static struct x_info x_ids[] = {
{ "root", x_ROOT, },
{ "system", x_SYSTEM, },
{ "radio", x_RADIO, },
{ "bluetooth", x_BLUETOOTH, },
{ "graphics", x_GRAPHICS, },
};

#else

static struct x_info y_ids[] = {
{ "root", y_ROOT, },
{ "system", y_SYSTEM, },
{ "radio", y_RADIO, },
{ "bluetooth", y_BLUETOOTH, },
{ "graphics", y_GRAPHICS, },
};

#endif

when i execute my program, based on command flag , it should fall
into one of the #if or else condition?

Is it possible to do? any other way around? basically i want to put
conditional breaks to some of my structures when first time executes
with conditional flags.

Please help me!

-Ram
 
L

luserXtrog

Hi,

I have some code in my header file like this:

#if defined(some #define variable)

static struct x_info x_ids[] = {
    { "root",      x_ROOT, },
    { "system",    x_SYSTEM, },
    { "radio",     x_RADIO, },
    { "bluetooth", x_BLUETOOTH, },
    { "graphics",  x_GRAPHICS, },
 };

#else

static struct x_info y_ids[] = {
    { "root",      y_ROOT, },
    { "system",    y_SYSTEM, },
    { "radio",     y_RADIO, },
    { "bluetooth", y_BLUETOOTH, },
    { "graphics",  y_GRAPHICS, },
 };

#endif

when i execute my program, based on command flag , it should  fall
into one of the #if or else condition?

Um. A few scattered points.
Pre-processing is part of compilation, not execution.
The #if condition controls whether the section of code is
included in the compilation or not. There is no falling.
You can define the variable (or not) on the command line
when compiling. If the program needs to use command line
arguments, it must process them itself.
Is it possible to do? any other way around? basically i want to put
conditional breaks to some of my structures when first time executes
with conditional flags.

You can compile two versions and run one of them once, and the other
thereafter. A structure is a spatial artifact, not a temporal one.
I do not understand what it means to put a break to a structure.
Please help me!

One does what one can.
 
N

Nick Keighley

Subject: setting the pre-processor variable during execution time..

this is, of course, impossible. The preprocessor runs before
"the compiler proper"[1]. Hence preprocessor (#define) identifiers are
not available when the program runs.


I have some code in my header file like this:

#if defined(some #define variable)

static struct x_info x_ids[] = {
    { "root",      x_ROOT, },
    { "system",    x_SYSTEM, },
    { "radio",     x_RADIO, },
    { "bluetooth", x_BLUETOOTH, },
    { "graphics",  x_GRAPHICS, },
 };

#else

static struct x_info y_ids[] = {
    { "root",      y_ROOT, },
    { "system",    y_SYSTEM, },
    { "radio",     y_RADIO, },
    { "bluetooth", y_BLUETOOTH, },
    { "graphics",  y_GRAPHICS, },
 };

#endif

I find this a bit odd. I'd have expected the code to use
the same identifier. That is not x_ids and y_ids but simply

static struct x_info ids[] = {

that is two different sets of presets for the same identifier

when i execute my program, based on command flag , it should  fall
into one of the #if or else condition?

yes. It must do this
Is it possible to do?

to do what?
any other way around? basically i want to put
conditional breaks to some of my structures when first time executes
with conditional flags.

sorry you lost me. A run-time way to do it might be

static struct x_info x_ids[] = {
{ "root", x_ROOT, },
{ "system", x_SYSTEM, },
{ "radio", x_RADIO, },
{ "bluetooth", x_BLUETOOTH, },
{ "graphics", x_GRAPHICS, },
};

static struct x_info y_ids[] = {
{ "root", y_ROOT, },
{ "system", y_SYSTEM, },
{ "radio", y_RADIO, },
{ "bluetooth", y_BLUETOOTH, },
{ "graphics", y_GRAPHICS, },
};


static struct x_info ids[MAX_INFO];

if (some_runtime == X)
for (i = 0; i < MAX_INFO; i++)
ids = x_ids;
else
for (i = 0; i < MAX_INFO; i++)
ids = y_ids;


This way you select x or y depending on some runtime condition.
I've no idea if this is what you wanted.

[1] the standard dresses it up in more complex (precise)
language. The pre-processor is a very early stage of the
"translation process". But it all amounts to the same thing.


--
Look, I am French, and even worst, I live in Paris. I know
something about fads really.
Jacob Navia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top