majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Add header file inclusion guards #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
'#pragma once' is not well supported beyond MSVC and recent versions of GCC. By 
providing header 
guards as well as #pragma once, one can obtain both the performance benefit of 
#pragma once, and 
wider  portability.

See: http://en.wikipedia.org/wiki/Pragma_once#Advantages_and_disadvantages

Original issue reported on code.google.com by swiftcoder on 29 Jul 2009 at 6:15

GoogleCodeExporter commented 9 years ago
My standard practice, especially with external library headers, is to use a 
generated
UUID value (with underscores substituted for dashes) as part of the header guard
#define name.  If all external header names are unique, one UUID can be used in
combination with the header file name for the whole project.

An example would be:
{{{
#pragma once

#ifndef YAML_H_32DC4090_EB12_4bb6_8366_5A5F9A71B700
#define YAML_H_32DC4090_EB12_4bb6_8366_5A5F9A71B700

// Header contents go here

#endif // YAML_H_32DC4090_EB12_4bb6_8366_5A5F9A71B700
}}}

This way, no reasonable project will have header guard conflicts with the 
yaml-cpp
library.

Original comment by rtweeks21 on 29 Jul 2009 at 6:27

GoogleCodeExporter commented 9 years ago
Good idea. I've only ever used MSVC and gcc, so I've never quite known how 
portable
it is. And thanks, rtweeks, for the UUID suggestion.

Original comment by jbe...@gmail.com on 29 Jul 2009 at 10:32