Re: reasons for having no inclusion guards in config.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/7/2010 2:40 PM, Tim Rice wrote:
On Sun, 7 Mar 2010, John Calcote wrote:

On 3/7/2010 11:53 AM, Bob Friesenhahn wrote:
[...]
There may be several config.h files, each of which has somewhat different
content.  Bing!
So what would be wrong with generating an include guard tag based on the name
of the project?

For instance,

--------
#ifndef GRAPHICSMAGICK_CONFIG_H
#define GRAPHICSMAGICK_CONFIG_H

...

#endif
--------

John
To give a real world example, in freeradius there are
src/modules/rlm_counter/config.h.in
src/modules/rlm_eap/types/rlm_eap_peap/config.h.in
src/modules/rlm_eap/types/rlm_eap_tls/config.h.in
src/modules/rlm_eap/types/rlm_eap_ttls/config.h.in
src/modules/rlm_example/config.h.in
src/modules/rlm_ippool/config.h.in
src/modules/rlm_pam/config.h.in
src/modules/rlm_perl/config.h.in
src/modules/rlm_radutmp/config.h.in
src/modules/rlm_smb/config.h.in
src/modules/rlm_smsotp/config.h.in
src/modules/rlm_sql/drivers/rlm_sql_mysql/config.h.in
src/modules/rlm_sqlhpwippool/config.h.in
src/modules/rlm_unix/config.h.in

It would work to have each of those with
#ifndef FREERADIUS_CONFIG_H
#define FREERADIUS_CONFIG_H
....
#endif

Clearly not. I wasn't considering the case where there were multiple config.h files in the *same* project. I assumed Bob was talking about including config.h files from different projects. Now I see that that would be a problem.

Regardless, there are ways around this issue. All config.h files can't be in the same directory, even if in the same project. So a path-based include-guard symbol could be generated, e.g.,

#ifndef SRC_MODULES_RLM_COUNTER_CONFIG_H
...

The idea here of course is that the unwanted situation whereby the same config.h file is inadvertently included in the same translation unit twice could be avoided.

As an aside: It's interesting to note that gcc's preprocessor has built-in functionality to automatically guard against this situation.

John



_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux