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 584228 - const int compiles into unparenthesized define
const int compiles into unparenthesized define
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: general
0.7.x
Other Linux
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-05-29 19:05 UTC by Adam Dingle
Modified: 2009-06-26 06:25 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Adam Dingle 2009-05-29 19:05:11 UTC
I'm using Vala 0.7.3.

The compiler turns a const int into a #define which is not surrounded by parentheses, yielding trouble.

To see the problem:

==
const int sum = 2 + 2;

void main() {
    stdout.printf("%d\n", 2 * sum);
}
==

The program prints 6, which is wrong.  The generated .c file contains the following:

#define sum 2 + 2
Comment 1 Jürg Billeter 2009-06-26 06:25:25 UTC
commit d6dbfa265da427618cac87365cdf0a39f01c3f0c
Author: Jürg Billeter <j@bitron.ch>
Date:   Thu Jun 25 19:12:34 2009 +0200

    Add parenthesis to macro substitutions where necessary
    
    Based on patch by Yu Feng.