After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 618857 - Invalid pointer asignment in structure initialization
Invalid pointer asignment in structure initialization
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
unspecified
Other All
: Urgent critical
: ---
Assigned To: Vala maintainers
Vala maintainers
accepts-invalid invalid-c-code
Depends on:
Blocks:
 
 
Reported: 2010-05-17 09:32 UTC by pancake
Modified: 2014-06-27 02:05 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description pancake 2010-05-17 09:32:57 UTC
Here's a sample code that passes vala compiler, but fails when compiling C:

   struct Foo { string foo; void *ptr; }
   void *poing = null;
   const Foo foo = { "foo", poing };
   void main() {}

This code doesn't compiles and reports the following error:
  error: initializer element is not constant (near initialization for â)

The fix required to compile in C is:
   Fixing C code:
    - const Foo foo = {"foo", poing};
    + const Foo foo = {"foo", &poing};

Same for vala:
   Fixing in Vala code:
      const Foo foo = { "foo", &poing };

I think vala should allow this syntax and put the '&' in the generated C code.
Comment 1 pancake 2010-06-04 10:43:12 UTC
Maybe this bug is related with https://bugzilla.gnome.org/show_bug.cgi?id=618933
Comment 2 Jürg Billeter 2010-06-05 09:19:05 UTC
I don't think that valac should implicitly take the address in this case. If you want to store the pointer to the variable instead of the contents, you should really use `&'. The compiler should be fixed to report an error when non-constant expressions are used in constant initializers.
Comment 3 Evan Nemerson 2014-06-27 02:05:54 UTC
test.vala:3.17-3.17: error: Value must be constant
const Foo foo = { "foo", poing };
                ^
Compilation failed: 1 error(s), 0 warning(s)


It has been doing this for a while, I think since


commit 6f12ba028dd6442afa25728e530516af7d8a6f0e
Author: Jürg Billeter <j@bitron.ch>
Date:   Tue Feb 8 19:59:25 2011 +0100

    Report error for constants with non-constant expressions