Add dead weight to C++ sizeof values

This commit is contained in:
Nigel Tao committed 2020-01-11 11:41:24 +11:00
1 parent 2fff7c782f
commit 4b669a4181
2 files changed
+80

No files matched your search

+10
View File
@@ -1077,6 +1077,16 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error {
b.printf("%s() = delete;\n", fullStructName)
b.printf("%s(const %s&) = delete;\n", fullStructName, fullStructName)
b.printf("%s& operator=(const %s&) = delete;\n", fullStructName, fullStructName)
b.writes("\n")
b.writes("// As above, the size of the struct is not part of the public API, and unless\n")
b.writes("// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap\n")
b.writes("// allocated, not stack allocated. Its size is not intended to be known at\n")
b.writes("// compile time, but it is unfortunately divulged as a side effect of\n")
b.writes("// defining C++ convenience methods. Use \"sizeof__T()\", calling the function,\n")
b.writes("// instead of \"sizeof T\", invoking the operator. To make the two values\n")
b.writes("// different, so that passing the latter will be rejected by the initialize\n")
b.writes("// function, we add an arbitrary amount of dead weight.\n")
b.writes("uint8_t dead_weight[123000000]; // 123 MB.\n")
b.writes("#endif // (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)\n\n")
// The empty // comment makes clang-format place the function name