[prog] C++ strange linking behaviour
Kathryn Hogg
kjh at flyballdogs.com
Tue Nov 9 10:19:03 EST 2004
Meredith L. Patterson said:
> then you can be assured that you won't define methods multiple times; if
> somewhere in the compilation chain it turns out you have "someclass.h"
> included more than once, the first time it'll define the macro
> _SOMECLASS_H (which never expands into anything; you can safely think of
> it as a boolean value) and include the header, then the second time the
> preprocessor will see that _SOMECLASS_H has been defined, it'll skip
> down to the #endif, and you're safe. :)
I usually recommend that people use some kind organization prefix on their
gaurd macros. On large projects. I have seen cases where some external
code uses the same guard macros which can break things if I end up
including both of them.
So, I'd use #ifndef KJH_SOMECLASS_H if my company/project was named KJH
I'm just going to be a little pedantic if no one minds. What you refer to
above is "declaring". This tells the compiler that something exists.
i.e.
int some_func(int);
declares the existence of the above named function. Headers are almost
exclusively declarations. In exactly one .C/.cpp./.cc/.cxx file, we need
to define the function:
int some_func(int)
{
return 0;
}
I know its slightly anal but being precise in language helps me sort
through people's problems at work.
--
Kathryn
http://womensfooty.com
More information about the Programming
mailing list