Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C error when initializing fixed-size array #22057

Closed
Checkmate6659 opened this issue Aug 16, 2024 · 2 comments · Fixed by #22059
Closed

C error when initializing fixed-size array #22057

Checkmate6659 opened this issue Aug 16, 2024 · 2 comments · Fixed by #22059
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Comptime Features processed during compile time, like $if, $for, $env etc Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@Checkmate6659
Copy link

Checkmate6659 commented Aug 16, 2024

V doctor:

V full version: V 0.4.7 f879368.384b5c4
OS: linux, Ubuntu 20.04.6 LTS
Processor: 8 cpus, 64bit, little endian, AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx

getwd: /home/enigma/vlang/bober_mini
vexe: /home/enigma/vlang/v/v
vexe mtime: 2024-08-16 08:21:55

vroot: OK, value: /home/enigma/vlang/v
VMODULES: OK, value: /home/enigma/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.25.1
Git vroot status: weekly.2024.33-11-g384b5c46
.git/config present: true

CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

What did you do?
./v -g -o vdbg cmd/v && ./vdbg src/board.v

module board

pub const n = u8(7)
pub const nsq = u16(n*n)

//Replace b with an empty board. b must be mutable.
//C error when trying to return a fixed-size array:
//https://github.com/vlang/v/issues/22056
pub fn empty_board(mut b [nsq]u8)
{
	b = [nsq]u8{init: 0}
}

//Clear screen.
pub fn clear_screen()
{
	print("\033[2J\033[1;1H")
}



What did you expect to see?

There is a C error when initializing a fixed-size array with {init: 0}. It is different depending on surrounding code: sometimes it is too many initializers, here it is ',' expected (got "*"), sometimes expression expected before '{' much later in the temporary C file

What did you see instead?

src/board.v:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
    1 | module board
      | ^
    2 | 
    3 | pub const n = u8(7)

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@spytheman
Copy link
Member

Current workaround: [nsq]u8{}.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Status: Confirmed This bug has been confirmed to be valid by a contributor. Comptime Features processed during compile time, like $if, $for, $env etc Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. labels Aug 16, 2024
@spytheman
Copy link
Member

The cgen problem can be shown using v -shared file.v .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Comptime Features processed during compile time, like $if, $for, $env etc Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants