#[solved] Understanding undefined

1 messages · Page 1 of 1 (latest)

keen wedge
#
const thing :u8= undefined;
```What does it mean to do this in Zig?
How is it different than other languages, and/or what is it doing exactly?
_(eg: I understand C, but have no clue how that would map to any C concept at all)_
twilit pecan
#

its the same as not giving a value to a variable in C

keen wedge
#

Also, is it the same as doing undefined for the default values of struct fields, or is that different?

twilit pecan
#

var n: c_int = undefined; == int n;

keen wedge
#

so if I try to read it it would be garbage, and not zero-initialized?

twilit pecan
#

yes

keen wedge
#

oh, well... not what I was looking for then

#

I was trying to avoid ?T= null basically

hybrid portal
#

xy problem perhaps. what do you want to do?

static flint
keen wedge
#
  const Result = struct {
    stdout  :Data,
    stderr  :Data,
    code    :u8= undefined,   // <------------
  }
```This being the returning error of a shell command
#

but if Data, aka ArrayList is uninitialized, then it will just be empty. but u8 0 initialized could mean success

hybrid portal
#

uninitalized does not mean "empty"

#

empty implies the array list is already initialized

keen wedge
#

Can you access an arraylist before its even ArrayList(T).init(allocator)?

#

if not, then its empty

keen wedge
#

empty-uninitialized, empty-initialized its both empty

#

0 is not empty, its success

#

big difference

#

that's what I was trying to solve

hybrid portal
#

i dont understand what you are trying to do

#

"u8 being initialized is success" does not sound like behavior you should rely on

hybrid portal
#

an uninitalized array list is nothing, you cant get anything meaningful out of it

keen wedge
#

in my brain, empty is just empty

#

"whatever version of empty this language technicalities implies as empty"

keen wedge
#

0 should NOT be synonym with empty, when 0 means success

#

and uninitialized means garbage, so not reliable either

hybrid portal
#

why not just use a boolean

#

why a u8

keen wedge
#

aka ?T= null is the only option

keen wedge
hybrid portal
#

isnt there a @boolFromInt?

twilit pecan
#

thats called != 0

keen wedge
#

why would I want to return a bool from a shell command?

hybrid portal
#

idk anything about shell commands, so idk

keen wedge
#

I want the exit code and a couple of strings

twilit pecan
keen wedge
#

I was asking if undefined is enough. which is not

#

its not that I don't want to, I just don't understand this lang, and asking how this lang works

#

[solved] Understanding undefined