[prog] C++ strange linking behaviour

Riccarda Cassini riccarda.cassini at gmx.de
Tue Nov 9 16:56:38 EST 2004


On Mon, Nov 08, 2004 at 08:00:56PM -0600, Kathryn Hogg wrote:
> 
> Without the guards, you have a compile that won't stop until you run out
> of fd's.
> 
> When you check if a declaration is identical above, what are you checking?
>  Raw character strings?  Some kind of parsed representation of the code?
> 
> What if the code is quite complex like a large class definition or
> template definition?


Thanks, Kathryn and Akkana. I see that the approach I suggested might
run into various more or less subtle problems...

Upon rethinking, I figure, it would make more sense to apply a similar
logic at the *file* level, rather than doing it at the individual
symbols level.  Then, you wouldn't even need to check for stuff being
identical, as I suppose source files can safely be assumed to remain
unchanged during compilation.

I guess, in almost all cases, the #ifndef idiom is wrapped around the
complete header file anyway... so the preprocessor keeps a table of
symbols (macro names) corresponding to header files.  In this case,
equivalent semantics could be achieved by automatically setting up a
lookup table of headers visited, with filenames (or full paths) being
the lookup keys.   Essentially, it's just that I find the current
practice somewhat tedious...  Why require programmers to supply the
guard macro boilerplate themselves?  Why not just do it automatically?
That's what computers are for :-)

If you really ever do need more sophisticated skipping semantics, you
could always still fiddle with preprocessor directives...

What I'm thinking of is something like perl handles it when you say
"use ..." or "require ...".  Here, I presume that perl simply keeps an
internal table[*] of modules already included (which is consulted and
updated every time a file is 'use'd).

So, with that redefinition (not redeclaration...:-) of my gut feeling
which prompted me to post in the first place, would there still be any
arguments in favor of having the programmer do it manually?

Riccarda

(btw, it's hardly 7 a.m. and I'm just having my first cup of coffee,
so this whole line of reasoning may not be wisest possible... :-)


[*] I suppose this table may just be the %INC hash, that's directly
accessible to the programmer to find out what modules actually have
been loaded, e.g.

for my $inc (sort keys %INC) { print "$inc : $INC{$inc}\n"; }


PS: <meta> it's nice to have place where you can ask these "what you
always wanted to know, but never dared to ask" type of questions,
without fear of being laughed at.  Just wanted to say that. </meta>



More information about the Programming mailing list