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 returning a fixed-size array (NOTE: initialization with a for loop doesn't help) #22056

Closed
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

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

pub fn empty_board() [nsq]u8
{
	return [nsq]u8{init: 0}
}

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



What did you expect to see?

A function returning a fixed size array of 49 u8 elements all containing 0

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 | 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.

@Checkmate6659 Checkmate6659 changed the title Cannot return a fixed-size array C error when returning a fixed-size array Aug 16, 2024
@Checkmate6659 Checkmate6659 changed the title C error when returning a fixed-size array C error when returning a fixed-size array (initialization is probably the issue) Aug 16, 2024
@Checkmate6659 Checkmate6659 changed the title C error when returning a fixed-size array (initialization is probably the issue) C error when returning a fixed-size array (initialization is probably the issue) (NOTE: next issue https://github.com/vlang/v/issues/22057 has more info) Aug 16, 2024
@Checkmate6659 Checkmate6659 changed the title C error when returning a fixed-size array (initialization is probably the issue) (NOTE: next issue https://github.com/vlang/v/issues/22057 has more info) C error when returning a fixed-size array (NOTE: initialization with a for loop doesn't help) Aug 16, 2024
@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. Comptime Features processed during compile time, like $if, $for, $env etc Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Aug 16, 2024
@spytheman
Copy link
Member

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

@spytheman
Copy link
Member

The current workaround is:

pub const n = 7
pub const nsq = n*n

@spytheman spytheman added the Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. label Aug 16, 2024
@felipensp felipensp self-assigned this Aug 16, 2024
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