Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
support global static const int
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 21, 2022
1 parent 3098765 commit b32fb1c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cl/type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ func compileVarDecl(ctx *blockCtx, decl *ast.Node, global bool) {
scope.Insert(types.NewVar(ctx.goNodePos(decl), ctx.pkg.Types, decl.Name, typ))
} else {
if (kind&parser.KindFConst) != 0 && isInteger(typ) && tryNewConstInteger(ctx, typ, decl) {
if static != "" {
substObj(ctx.pkg.Types, ctx.cb.Scope(), static, scope, decl.Name)
}
return
}
newVarAndInit(ctx, scope, typ, decl, global)
Expand Down
4 changes: 3 additions & 1 deletion testdata/init/init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <stdio.h>

static const int k = 1023;

int g_a = 100;

static int g_arr[][3];
Expand Down Expand Up @@ -29,7 +31,7 @@ int main() {

struct test_t z = test;

printf("a = %d, g_a = %d\n", a, g_a);
printf("a = %d, g_a = %d, k = %d\n", a, g_a, k);

printf("foo.a = %d, foo.b = %d\n", foo.a, foo.b);
printf("bar.a = %d, bar.b = %s\n", bar.a, bar.b);
Expand Down

0 comments on commit b32fb1c

Please sign in to comment.