2

Can I have more than one struct member per line?

I was making a struct. It seems like V enforces only one member per line. I don't recall seeing that mentioned anywhere.

trial.v:191:2: error: unknown type `` 
  189 |     fsize    int
  190 |     vers     int
  191 |     x,y,z    i16
      |     ~~
  192 |     c    int
aMike
  • 852
  • 5
  • 14

2 Answers2

4

It looks like you cannot use the comma shortcut in field declarations. For example, the following works:

struct S { x int y int z f32 }

fn main() {
    s := S { x: 10 y: 20 z: 3.14 }
} 
Timo
  • 9,269
  • 2
  • 28
  • 58
1

yeah, cannot use comma for the declaration of the struct, but it is ok to use for the initialization:

struct Xyz { x int y int z f32 }
fn main() {
    s := Xyz{ x: 11, y: 20, z: 3.14 }
    println(s.x)
}

Btw, name of a struct in V needs to start in uppercase and be at least 3 characters long.