在Eclipse CDT中,當新建頭文件的時候, include guard默認為文件名,例如:
[cpp]
/*
* test.h
*
* Created on: 2013-5-22
* Author: tao
*/
#ifndef TEST_H_
#define TEST_H_
#endif /* TEST_H_ */
/*
* test.h
*
* Created on: 2013-5-22
* Author: tao
*/
#ifndef TEST_H_
#define TEST_H_
#endif /* TEST_H_ */
但是為了更好的編程規范,我們需要將include guard中包含全路徑,例如:
[cpp]
/*
* test.h
*
* Created on: 2013-5-22
* Author: tao
*/
#ifndef PLATFORM_SUN6I_INCLUDE_TEST_H_
#define PLATFORM_SUN6I_INCLUDE_TEST_H_
#endif /* PLATFORM_SUN6I_INCLUDE_TEST_H_ */
/*
* test.h
*
* Created on: 2013-5-22
* Author: tao
*/
#ifndef PLATFORM_SUN6I_INCLUDE_TEST_H_
#define PLATFORM_SUN6I_INCLUDE_TEST_H_
#endif /* PLATFORM_SUN6I_INCLUDE_TEST_H_ */
修改 workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.ui.prefs
添加或修改如下值:
[plain]
codetemplates.includeGuardGenerationScheme=2
eclipse.preferences.version=1
formatter_settings_version=1
codetemplates.includeGuardGenerationScheme=2
eclipse.preferences.version=1
formatter_settings_version=1
codetemplates.includeGuardGenerationScheme的定義如下
0 大寫文件名, i.e. FILE_H_
1 生成 UUID, i.e. HA9BACDC2_C883_4331_846A_E3769E132E8A
2 大寫全路徑,i.e. SRC_INCLUDE_FILE_H_