[comp.sys.mac.programmer] Shadow of "shadow"

hvs@pender (H.V. Sorensen) (09/28/89)

I recently got the v. 4 of Think C (TC) and started programming. In one of my
programs I had a strange bug, which I found was caused by using the name
"shadow" for an integer variable. TC complains about an "illegal
re-decleration of variable" or something like that. To reproduce the problem
try to compile the program below:
     #include <stdio.h>
     int shadow;
     main()
     {
          printf("hello\n");
     }
I am using a "virgin" copy of TC4 with the ANSI library as only other file in
my project. By changing the name to anything but shadow, the program compiles
perfectly. Are there reserved words in TC that I am not aware of? If so are
there any other "reserved" words I should be aware of? Anybody out there with
an explanation?

Thanks,  Henrik Sorensen
******************************************************************************
*   Henrik Sorensen               Department of Electrical Enginering        *
*   Internet: hvs@ee.upenn.edu    University of Pennsylvania                 *
******************************************************************************

******************************************************************************
*   Henrik Sorensen               Department of Electrical Enginering        *
*   Internet: hvs@ee.upenn.edu    University of Pennsylvania                 *
******************************************************************************

siegel@endor.harvard.edu (Rich Siegel) (09/28/89)

In article <14784@netnews.upenn.edu> hvs@pender (H.V. Sorensen) writes:
>I recently got the v. 4 of Think C (TC) and started programming. In one of my
>programs I had a strange bug, which I found was caused by using the name
>"shadow" for an integer variable. TC complains about an "illegal
>re-decleration of variable" or something like that. To reproduce the problem

	"shadow" is a member of the Style enumeration, declared in QuickDraw.h.
Since you presumably have "use <MacHeaders>" turned on in your Options, 
the MacHeaders file, including these declarations, is automatically
included at the beginning of each file, hence the conflicting declarations.

R.



~~~~~~~~~~~~~~~
 Rich Siegel
 Staff Software Developer
 Symantec Corporation, Language Products Group
 Internet: siegel@endor.harvard.edu
 UUCP: ..harvard!endor!siegel

"There is no personal problem which cannot be solved by sufficient
application of high explosives."

~~~~~~~~~~~~~~~

pem@cadnetix.COM (Paul Meyer) (09/29/89)

In article <14784@netnews.upenn.edu> hvs@pender (H.V. Sorensen) writes:
>"shadow" for an integer variable. TC complains about an "illegal
>re-decleration of variable" or something like that. To reproduce the problem

>perfectly. Are there reserved words in TC that I am not aware of? If so are
>there any other "reserved" words I should be aware of? Anybody out there with
>an explanation?

	I have one.  No, TC doesn't reserve any words, but it does have
precompiled headers.  The standard precompiled stuff includes all the Mac
Toolbox stuff that a normal (or even moderately-advanced) Mac application
needs.  Among the precompiled files is the QuickDraw includes (I think
that's QuickDraw.h), which of course #defines "shadow" as a bit-mask value
for the text style type.  (In Pascal, you would get an error because the
identifier is already used in an enumerated type...).

	If you really don't plan to do Mac stuff with TC, you can make
your own precompiled header that doesn't do this; you can even replace
it with precompiling the ANSI library headers.  The stuff on how to do
this is in the TC manual, but I'll attempt to summarize below.  (I just
set up stuff to swap MacHeaders's myself recently, when working on NetHack
for my Mac BBS.)

	TC looks for a file called MacHeaders in the folder with the TC
application, and preloads it before every source file.  This is the only
form of header precompilation--you precompile one header file, and name
the output "MacHeaders" in the TC folder.  I suggest that the first thing
you do is copy the old MacHeaders so you can switch back to it to do Mac
things.  Then take a look at the structure of the file "Mac #includes.h",
in the TC folder, which is the source for the standard MacHeaders.  It's
basically a normal .h file that #includes all sorts of files from the
Mac #includes directory.  Now make up your own file that just includes all
the ANSI include files you commonly want.  While viewing it in TC, choose
"precompile" off the (I think) Project menu.  Store the output as something
like "ANSI MacHeaders" replace the original MacHeaders with a copy of ANSI
MacHeaders to run in non-Mac mode, and replace MacHeaders with a copy of
the saved original to go back to Mac mode.

	Alternatively, you could just patrol your code for uses of things
#defined in the Mac stuff, and carefully #undefine them before using the
words, but you would have to know what to look for (be familiar with Inside
Mac).
Paul Meyer                      pem@cadnetix.COM
Daisy/Cadnetix Inc. (DAZIX)	{uunet,boulder}!cadnetix!pem
5775 Flatirons Pkwy.            GEnie P.MEYER
Boulder, CO 80301               (303)444-8075x277