From 23da2128d574d530f2bc3d6898b4ce78f25f8f4e Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 14 Jun 2023 04:44:48 -0300 Subject: [PATCH] cgen: fix msvc packed attr (#18437) --- vlib/v/gen/c/cgen.v | 6 +++++- vlib/v/gen/c/struct.v | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index bd1ee02abc..00c6a4b1cc 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -3798,7 +3798,11 @@ fn (mut g Gen) enum_decl(node ast.EnumDecl) { g.enum_typedefs.writeln(', // ${cur_value}') cur_enum_offset++ } - packed_attribute := if node.typ != ast.int_type { '__attribute__((packed))' } else { '' } + packed_attribute := if !g.is_cc_msvc && node.typ != ast.int_type { + '__attribute__((packed))' + } else { + '' + } g.enum_typedefs.writeln('} ${packed_attribute} ${enum_name};') if node.typ != ast.int_type { g.enum_typedefs.writeln('#pragma pack(pop)\n') diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index 72004521e6..5e10a9f3b0 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -507,7 +507,7 @@ fn (mut g Gen) struct_decl(s ast.Struct, name string, is_anon bool) { } // g.type_definitions.writeln('} $name;\n') // - ti_attrs := if s.attrs.contains('packed') { + ti_attrs := if !g.is_cc_msvc && s.attrs.contains('packed') { '__attribute__((__packed__))' } else { ''