Pull struct definitions out of `extern "C"`
This avoids
https://developercommunity.visualstudio.com/t/Cryptic-error-message:-error-C2065:-__/1363621
diff --git a/internal/cgen/cgen.go b/internal/cgen/cgen.go
index 1c8ab53..af398b2 100644
--- a/internal/cgen/cgen.go
+++ b/internal/cgen/cgen.go
@@ -707,8 +707,7 @@
}
func (g *gen) genHeader(b *buffer) error {
- b.writes("\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n")
-
+ b.writes("\n")
b.writes("// ---------------- Status Codes\n\n")
wroteStatus := false
@@ -734,6 +733,8 @@
b.printf("typedef struct %s%s__struct %s%s;\n\n", g.pkgPrefix, structName, g.pkgPrefix, structName)
}
+ b.writes("#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n")
+
b.writes("// ---------------- Public Initializer Prototypes\n\n")
b.writes("// For any given \"wuffs_foo__bar* self\", \"wuffs_foo__bar__initialize(self,\n")
b.writes("// etc)\" should be called before any other \"wuffs_foo__bar__xxx(self, etc)\".\n")
@@ -794,6 +795,8 @@
return err
}
+ b.writes("#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
+
b.writes("// ---------------- Struct Definitions\n\n")
b.writes("// These structs' fields, and the sizeof them, are private implementation\n")
b.writes("// details that aren't guaranteed to be stable across Wuffs versions.\n")
@@ -806,9 +809,8 @@
return err
}
}
- b.writes("#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)\n")
+ b.writes("#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)\n\n")
- b.writes("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
return nil
}
diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c
index 4e5bf2c..f189ee3 100644
--- a/release/c/wuffs-unsupported-snapshot.c
+++ b/release/c/wuffs-unsupported-snapshot.c
@@ -5656,10 +5656,6 @@
} // extern "C"
#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
// ---------------- Public Consts
@@ -5668,6 +5664,10 @@
typedef struct wuffs_adler32__hasher__struct wuffs_adler32__hasher;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -5723,6 +5723,10 @@
wuffs_adler32__hasher* self,
wuffs_base__slice_u8 a_x);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -5832,14 +5836,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_bmp__error__bad_header[];
@@ -5854,6 +5850,10 @@
typedef struct wuffs_bmp__decoder__struct wuffs_bmp__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -5964,6 +5964,10 @@
wuffs_bmp__decoder__workbuf_len(
const wuffs_bmp__decoder* self);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -6179,14 +6183,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_cbor__error__bad_input[];
@@ -6216,6 +6212,10 @@
typedef struct wuffs_cbor__decoder__struct wuffs_cbor__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -6277,6 +6277,10 @@
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -6403,14 +6407,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
// ---------------- Public Consts
@@ -6419,6 +6415,10 @@
typedef struct wuffs_crc32__ieee_hasher__struct wuffs_crc32__ieee_hasher;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -6474,6 +6474,10 @@
wuffs_crc32__ieee_hasher* self,
wuffs_base__slice_u8 a_x);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -6582,14 +6586,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_deflate__error__bad_huffman_code_over_subscribed[];
@@ -6614,6 +6610,10 @@
typedef struct wuffs_deflate__decoder__struct wuffs_deflate__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -6680,6 +6680,10 @@
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -6849,14 +6853,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_lzw__error__bad_code[];
@@ -6869,6 +6865,10 @@
typedef struct wuffs_lzw__decoder__struct wuffs_lzw__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -6939,6 +6939,10 @@
wuffs_lzw__decoder__flush(
wuffs_lzw__decoder* self);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -7082,14 +7086,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_gif__error__bad_extension_label[];
@@ -7121,6 +7117,10 @@
typedef struct wuffs_gif__decoder__struct wuffs_gif__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -7231,6 +7231,10 @@
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -7505,14 +7509,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_gzip__error__bad_checksum[];
@@ -7528,6 +7524,10 @@
typedef struct wuffs_gzip__decoder__struct wuffs_gzip__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -7589,6 +7589,10 @@
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -7715,14 +7719,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_json__error__bad_c0_control_code[];
@@ -7788,6 +7784,10 @@
typedef struct wuffs_json__decoder__struct wuffs_json__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -7849,6 +7849,10 @@
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -7984,14 +7988,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_nie__error__bad_header[];
@@ -8005,6 +8001,10 @@
typedef struct wuffs_nie__decoder__struct wuffs_nie__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -8115,6 +8115,10 @@
wuffs_nie__decoder__workbuf_len(
const wuffs_nie__decoder* self);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -8300,14 +8304,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_zlib__note__dictionary_required[];
@@ -8325,6 +8321,10 @@
typedef struct wuffs_zlib__decoder__struct wuffs_zlib__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -8395,6 +8395,10 @@
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -8536,14 +8540,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_png__error__bad_checksum[];
@@ -8561,6 +8557,10 @@
typedef struct wuffs_png__decoder__struct wuffs_png__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -8671,6 +8671,10 @@
wuffs_png__decoder__workbuf_len(
const wuffs_png__decoder* self);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -8915,14 +8919,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// ---------------- Status Codes
extern const char wuffs_wbmp__error__bad_header[];
@@ -8935,6 +8931,10 @@
typedef struct wuffs_wbmp__decoder__struct wuffs_wbmp__decoder;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
@@ -9045,6 +9045,10 @@
wuffs_wbmp__decoder__workbuf_len(
const wuffs_wbmp__decoder* self);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
@@ -9236,10 +9240,6 @@
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#if defined(__cplusplus) && (__cplusplus >= 201103L)
// ---------------- Auxiliary - Base