GNOME Bugzilla – Bug 618856
Not possible to define a global pointer to a symbol
Last modified: 2018-05-22 13:35:22 UTC
While this construction is valid in C, it isnt possible under Vala. Here's a test program: void main() { void * foo = &main; // shouldn't this be a valid expression in vala? } a.vala:2.13-2.13: error: syntax error, expected `;' const void * foo = &main; When dropping the ampersand: a.vala:2.9-2.18: error: Assignment: Cannot convert from `main' to `void*' void * foo = main; So we force the casting as suggested: void *foo=(void*)main; And it compiles. But moving the variable definition to the global context: a.vala:1.1-1.10: error: Non-constant field initializers not supported in this context void * foo = (void*)main; So I add 'const', and that's what I get: a.vala:1.1-1.31: error: `void*' not supported as type for constants const void * foo = (void*)main; and [pancake@bitbox prg]$ valac a.vala a.vala:1.27-1.30: error: syntax error, expected `)' const void * foo = (const void*)main;
There are two separate problems. The first one is missing implicit typecast to void*. That may be a design decision, but I don't know for sure. The second is that the function pointer is not considered a constant, while it should be. That should be fairly trivial to fix.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/97.