pre defined variables


 
Thread Tools Search this Thread
Top Forums Programming pre defined variables
# 1  
Old 11-28-2005
pre defined variables

Hi

First I want to explain the scenerio :
In my project I want to control the printing of some messages. Thats why I use
#ifdef MESSAGE
------------print message--------------
#endif

And when I compile the program with -DMESSAGE option, it shows all message and without -DMESSAGE option it shows nothing. thats fine.

But this thing I want to control at run-time, mean if I execute the program like

./demo MESSAGE (it should show all the messages)
./demo (it should not show any message)

thanks
# 2  
Old 11-28-2005
Just a thought.

Why dont you define MESSAGE in the env and make a check for it in your application using the getenv("MESSAGE") call. That should simplify things.
# 3  
Old 11-29-2005
Just to confirm that there is absolutely no way to change the preprocessor at runtime. The preprocessor only runs once, during compile time; to change what the preprocessor sees, you must recompile.
# 4  
Old 11-30-2005
thanks for your valuable explaination.

Now I am controlling the printing the message with normal if-else.

And one more thing : Should logging controlled with nornal if-else or preprocessor controled if-else ?
# 5  
Old 11-30-2005
This is what we do in one of our application.

We have a config file which keeps all the user's preferences.

If there is an entry like

Code:
DEBUG=1

then in-side our code all those lines in

Code:
#ifdef DEBUG
print some debug statements 
#endif

gets printed.

vino
# 6  
Old 11-30-2005
thanks vino.

But what I want to ask is what is the STANDARD way to do this thing?

your way or by normal if-else.
# 7  
Old 11-30-2005
I doubt there is a standard way. You can do it the way you like.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How are environment variables defined in a Gnome terminal session?

Hello... and thanks in advance for any help anyone can offer me with my question! I'm hoping someone will have a little patience with me and walk me through this! I'm trying to understand a user login process on Centos 7 and I've gotten a bit confused trying to figure out when/how a Gnome... (4 Replies)
Discussion started by: bodisha
4 Replies

2. Shell Programming and Scripting

How to write bash script to subdivide a given subnet into a pre-defined number of smaller subnets?

Bash script to subdivide a given subnet into a pre-defined number of smaller subnets. Show network/broadcast address, number of hosts and assign gateway. For example: Input: ./subnetter.sh 192.168.0.0/24 3 Output: 192.168.0.0/128 subnet 192.168.0.0 broadcast 192.168.0.127 gateway... (1 Reply)
Discussion started by: mail2rias
1 Replies

3. Shell Programming and Scripting

How to write bash script to subdivide a given subnet into a pre-defined number of smaller subnets?

Bash script to subdivide a given subnet into a pre-defined number of smaller subnets. Show network/broadcast address, number of hosts and assign gateway. For example: Input: ./subnetter.sh 192.168.0.0/24 3 Output: 192.168.0.0/128 subnet 192.168.0.0 broadcast 192.168.0.127 gateway... (1 Reply)
Discussion started by: mail2rias
1 Replies

4. Shell Programming and Scripting

Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example $GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies

5. Shell Programming and Scripting

Need an automated pre-defined file pickup method

Hi Gurus, I need to develop a script which picks the files in a pre-defined order. The files from monday-friday will be named as abc_01_20130923 as monday's file and abc_02_20130924 as tuesday's..so..so forth till friday's which will be named as abc_05_20130927.It repeats over for the... (3 Replies)
Discussion started by: vikramgk9
3 Replies

6. AIX

Harddisk1 => Defined

I have an IBM 9110-51A p Series Server with AIX 5.3. It has 2 scsi hard disks hdisk0 and hdisk1 (and 4 on disk array). hdisk1 for few days ago is "Defined". When hdisk1 began "defined" i have a new one unknown disk "available" which called hdisk6. The left led of the case of hdisk1 on the... (4 Replies)
Discussion started by: stetsip
4 Replies

7. UNIX for Dummies Questions & Answers

user defined commands

Hi, i would like to create user defined commands. e,g: if an user executes , mkdircd test then a directory called test should be created and it should be cd to test. How i can create the command mkdircd with below action: mkdir $1 && cd $1. Please help me in achieving this (7 Replies)
Discussion started by: pandeesh
7 Replies

8. Shell Programming and Scripting

Crontab jobs don't see variables defined in /etc/profile

Is it true that Crontab jobs don't see variables defined in /etc/profile? How to get around that? (4 Replies)
Discussion started by: proactiveaditya
4 Replies

9. Shell Programming and Scripting

Ramdisk already defined

I am trying to mount the ramdisk for sorting, and i get the message "ramdisk already defined." What exactly is /dev/ramdisk0 and is it safe to remove it? # command sudo -S mktd 60 <<EOF initiate EOF # block of code for mktd ... && { print "ramdisk already defined." ... (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

10. Shell Programming and Scripting

awk printf for user defined variables

I am working on a SunFire 480 - uname -a gives: SunOS bsmdb02 5.9 Generic_112233-08 sun4u sparc SUNW,Sun-Fire-480R I am tyring to sum up the total size of all the directories for each running database using awk: #!/usr/bin/ksh for Database in `ps -efl | grep "ora_pmon" | grep -v grep |... (1 Reply)
Discussion started by: jabberwocky
1 Replies
Login or Register to Ask a Question