Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • vala vala
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 804
    • Issues 804
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 84
    • Merge requests 84
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
    • Model experiments
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • valavala
  • Issues
  • #1364

`glib.h` should be included in C code when there is `true` or `false` in Vala code

true and false are gboolean so glib.h should also be included.

A simple example:

#/usr/bin/env vala
void main() {
    if (true) {
        stdout.printf("test");
    }
}

And it will throw out errors:

/tmp/temptest.vala.XXDIT1.c: In function '_vala_main':
/tmp/temptest.vala.XXDIT1.c:11:13: error: 'TRUE' undeclared (first use in this function)
   11 |         if (TRUE) {
      |             ^~~~
/tmp/temptest.vala.XXDIT1.c:11:13: note: each undeclared identifier is reported only once for each function it appears in
error: cc exited with status 256

Another example without obvious true or false:

#!/usr/bin/env -S vala
void main() {
    while (1 == 1) {
        stdout.printf("test");
    }
}

And the errors are:

/tmp/temptest.vala.9S2JT1.c: In function '_vala_main':
/tmp/temptest.vala.9S2JT1.c:11:16: error: 'TRUE' undeclared (first use in this function)
   11 |         while (TRUE) {
      |                ^~~~
/tmp/temptest.vala.9S2JT1.c:11:16: note: each undeclared identifier is reported only once for each function it appears in
error: cc exited with status 256

Using vala without glib may not be so common, but it makes the language uncritical. glib.h should also be included in these situations or we may use 1 and 0 to replace true and false (or to define macros) if glib.h is not included.

Edited Oct 03, 2022 by 周 乾康
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking