BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need help with #if defined() used with SET environment VARIA

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Command Line Tools)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Mar 17, 2007 11:56 pm    Post subject: Need help with #if defined() used with SET environment VARIA Reply with quote



I'm using bcc32 5.5.1 on WinXP. Can someone help with doing a #if
defined(MY_SET_VAR) test at compile time. MY_SET_VAR is set with SET
MY_SET_VAR=5 from the WinXP command line. I am trying the simple
program:

First, from the command line, I do:

set MY_SET_VAR=5

Then compile:

int main() {

#if defined(MY_SET_VAR)
printf ("MY_SET_VAR"=%i\n", MY_SET_VAR );
#else
printf ("MY_SET_VAR does not exist.\n");
#endif


return 0;
}

Then run and program always prints that MY_SET_VAR does not exist.

I'm working on some programs that suggest this is possible in some
way, but I don't know.

Thanks.
Back to top
Ed Mulroy
Guest





PostPosted: Sun Mar 18, 2007 12:17 am    Post subject: Re: Need help with #if defined() used with SET environment V Reply with quote



Quote:
MY_SET_VAR is set with
SET MY_SET_VAR=5 from the WinXP command line

Then MY_SET_VAR is an item in the operating system environment and available
for use on command lines given to the operating system. However C and C++
macros are defined in the program and not in the operating system
environment.

To have it defined in your program put this in the source code prior to
where the macro is used.

#define MY_SET_VAR 5

If writing in C++ doing this instead is an alternative and is in some ways.

const int MY_SET_VAR = 5;

.. Ed

Quote:
irvpaton wrote in message
news:1174157780.807471.246210 (AT) l77g2000hsb (DOT) googlegroups.com...

I'm using bcc32 5.5.1 on WinXP. Can someone help with doing a #if
defined(MY_SET_VAR) test at compile time. MY_SET_VAR is set with SET
MY_SET_VAR=5 from the WinXP command line. I am trying the simple
program:

First, from the command line, I do:

set MY_SET_VAR=5

Then compile:

int main() {

#if defined(MY_SET_VAR)
printf ("MY_SET_VAR"=%i\n", MY_SET_VAR );
#else
printf ("MY_SET_VAR does not exist.\n");
#endif

return 0;
}

Then run and program always prints that MY_SET_VAR does not exist.

I'm working on some programs that suggest this is possible in some
way, but I don't know.
Back to top
Michel Leunen
Guest





PostPosted: Sun Mar 18, 2007 1:16 am    Post subject: Re: Need help with #if defined() used with SET environment V Reply with quote



irvpaton (AT) gmail (DOT) com wrote:

Quote:
I'm working on some programs that suggest this is possible in some
way, but I don't know.

Besides what Ed told you, you can try

set MY_SET_VAR=5

and then run this:

#include <iostream>
#include <stdlib.h>
#include <conio.h>

int main(void)
{
if (getenv("MY_SET_VAR")==NULL)
std::cout<<"MY_SET_VAR does not exist.\n"<<std::endl;
else
std::cout<<"MY_SET_VAR="<<getenv("MY_SET_VAR")<<std::endl;

getch();
return 0;
}

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
Back to top
Guest






PostPosted: Sun Mar 18, 2007 10:04 pm    Post subject: Re: Need help with #if defined() used with SET environment V Reply with quote

Thanks both for the good replies. However, I was working with a
prewritten system and it had the #if defined(MY_SET_VAR) to control
things during compile. Someone told me to do this type of thing:

bcc32 -DMY_SET_VAR=5 mycfile.c

which did work.

Irv
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Command Line Tools) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.