Switch to using header guards and add c linkage
This commit is contained in:
parent
1f22745e05
commit
bc0816e76d
@ -213,7 +213,13 @@ class CHeader(CFile):
|
|||||||
funcs: list[CFunc] = field(default_factory=list)
|
funcs: list[CFunc] = field(default_factory=list)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
pragma = "#pragma once\n\n"
|
name_upper = self.name.upper()
|
||||||
|
header_guard_name = f"{name_upper}_H"
|
||||||
|
header_guard_open = f"#ifndef {header_guard_name}\n#define {header_guard_name}\n\n"
|
||||||
|
header_guard_close = f"#endif // !{header_guard_name}\n"
|
||||||
|
|
||||||
|
c_linkage_open = "#ifdef __cplusplus\nBEGIN_C_LINKAGE\n#endif // !__cplusplus"
|
||||||
|
c_linkage_close = "#ifdef __cplusplus\nEND_C_LINKAGE\n#endif // !__cplusplus"
|
||||||
|
|
||||||
includes = _get_includes_string(self.includes)
|
includes = _get_includes_string(self.includes)
|
||||||
|
|
||||||
@ -231,7 +237,7 @@ class CHeader(CFile):
|
|||||||
for func in self.funcs:
|
for func in self.funcs:
|
||||||
funcs += func.declare()
|
funcs += func.declare()
|
||||||
|
|
||||||
return pragma + includes + forward_declarations + types + funcs
|
return header_guard_open + includes + c_linkage_open + forward_declarations + types + funcs + c_linkage_close + header_guard_close
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
Loading…
Reference in New Issue
Block a user