1
io = {};
io.wchar = 111111;
debug((string)io.wchar); // (null)

So the problem here is that io.wchar is still null. You can look at the whole class here: https://github.com/stsdc/monitor/blob/dev/src/Managers/Process.vala

1

I think the issue is you are using a cast, try using io.wchar.to_string() [https://valadoc.org/glib-2.0/uint64.to_string.html]

Edit: This worked for me based on your code, casting gave me a segfault.

struct Monitor.IO {
    public uint64 wchar;
}

int main (string[] args) {
    Monitor.IO io = {};
    io.wchar = 111111;
    warning (io.wchar.to_string ()); // Struct.vala:9: 111111

    return 0;
}
| improve this answer | |
  • In my case it showed 0. And also, please note, that I'm using this inside a class. Maybe there is something wrong with a declaration? – stsdc Jan 5 at 23:59
  • I would try switching to just defining the property, rather than using get; set; I think there is an issue there but I do not know what. – Thalexander Jan 6 at 1:17
  • Okay, I ran your code, I think you need those two changes and it works for me. – Thalexander Jan 6 at 1:24
  • 1
    I think io.wchar = 111111; is getting a copy of io as it is running (io.get().wchar, where get passes a copy not a reference), and then changing the value of wchar of the copy, and then the printing is getting a new copy of io, but the modified version is not being set. – Thalexander Jan 6 at 1:55
0

Two possible solutions:

  1. Boxing: IO? io { get; set; default = IO(); } Note the question mark. (Solution by David Hewitt)
  2. Removing get/set: IO io; (Solution by thalexander)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.