Discussion:
Treat undeclared macro constants as zero?
(too old to reply)
Sin Jeong-hun
2009-08-19 01:00:54 UTC
Permalink
Hello.

Is it possible to configure the preprocessor so that when it
encounters some undeclared macro constant in the C code then it
replaces it with zero? The situation is complicated but basically we
have some master "configuration file" which is actually a c file that
has all values as macro constants. Each time someone adds a new macro
constant to the master configuration file, we must update all other
branch configuration files accordingly by putting zeros for the
constant, because zero means it's not supported. So, if the
preprocessor replaces undeclared macro constants with zero
automatically, then it would be a lot easier.
Victor Bazarov
2009-08-19 01:09:54 UTC
Permalink
Post by Sin Jeong-hun
Is it possible to configure the preprocessor
No. There is nothing really you can change aside from the command line
switches: to define a macro and optionally give it a value and tell the
preprocessor where to look for files when a full path is not specified.
The preprocessor is not open for "configuring". Macros that are not
defined are not defined.
Post by Sin Jeong-hun
so that when it
encounters some undeclared macro constant in the C code then it
replaces it with zero? The situation is complicated but basically we
have some master "configuration file" which is actually a c file that
has all values as macro constants. Each time someone adds a new macro
constant to the master configuration file, we must update all other
branch configuration files accordingly by putting zeros for the
constant, because zero means it's not supported. So, if the
preprocessor replaces undeclared macro constants with zero
automatically, then it would be a lot easier.
What if you just include that "master configuration file" in all other
files? That way all your macros are magically defined... And there is
no need to do it again manually in more than one place - that's what the
include (header) files are for. Or maybe I'm just crazy, of course.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Doug Harrison [MVP]
2009-08-19 01:28:32 UTC
Permalink
On Tue, 18 Aug 2009 18:00:54 -0700 (PDT), Sin Jeong-hun
Post by Sin Jeong-hun
Hello.
Is it possible to configure the preprocessor so that when it
encounters some undeclared macro constant in the C code then it
replaces it with zero? The situation is complicated but basically we
have some master "configuration file" which is actually a c file that
has all values as macro constants. Each time someone adds a new macro
constant to the master configuration file, we must update all other
branch configuration files accordingly by putting zeros for the
constant, because zero means it's not supported. So, if the
preprocessor replaces undeclared macro constants with zero
automatically, then it would be a lot easier.
I'm not sure what you're asking. If a macro isn't declared, how is the
compiler supposed to know it's a macro and not, say, a misspelled variable?
Note that inside preprocessor directives like #if, an undeclared macro is
treated as 0.
--
Doug Harrison
Visual C++ MVP
Pavel A.
2009-08-19 01:26:32 UTC
Permalink
Post by Sin Jeong-hun
Hello.
Is it possible to configure the preprocessor so that when it
encounters some undeclared macro constant in the C code then it
replaces it with zero? The situation is complicated but basically we
have some master "configuration file" which is actually a c file that
has all values as macro constants. Each time someone adds a new macro
constant to the master configuration file, we must update all other
branch configuration files accordingly by putting zeros for the
constant, because zero means it's not supported. So, if the
preprocessor replaces undeclared macro constants with zero
automatically, then it would be a lot easier.
This seems already to be the default behavior of VC2008, and also GNU C.


--pa
Nathan Mates
2009-08-19 02:27:32 UTC
Permalink
Post by Sin Jeong-hun
Is it possible to configure the preprocessor so that when it
encounters some undeclared macro constant in the C code then it
replaces it with zero?
Given that warning C4668 ( see
http://msdn.microsoft.com/en-us/library/4dt9kyhy%28VS.80%29.aspx )
exists, and is off by default, it seems that what you ask for is
already the default.

Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Loading...