Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9324947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:43:35+00:00 2026-06-19T04:43:35+00:00

The land Vala provides enumerations. But these cannot be defined locally to a sub‑program.

  • 0

The land

Vala provides enumerations. But these cannot be defined locally to a sub‑program. Constants can be defined locally to a sub‑program, but seems to not be treated as static expressions (pseudo constants so).

The case

I have some sub‑programs implemented as state machines built with switch statements. I use some switch (state) { … } and want to use some constant for the case statements, as in case initial_state: { … }. This is recommended I believe, as it is more readable and maintainable than using literal constants as in case 0: { … }.

I tried to defined these constants inside the sub‑program, using declarations like const int initial_state = 0;. But Vala complains at each case statements. I tried to define an enumerations for the states, as in enum State { initial_state, … };, but Vala reject this as a syntax error and seems to only allows enumerations declarations outside of sub‑programs.

So far, I have to either define all states enumerations as external to the sub‑programs, or else to define constants inside the sub‑programs, but then have to use if constructs instead of switch constructs, as it’s OK for the if condition expression, to not be static.

The question

Do Vala allows to define static constants (of a scalar type) locally to a sub‑program in some way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:43:36+00:00Added an answer on June 19, 2026 at 4:43 am

    This is actually an error from gcc, not valac. Using this example:

    private void foo (int val) {
      const int one = 1;
      const int two = 2;
      const int three = 3;
    
      switch ( val ) {
        case one:
          GLib.debug ("One");
          break;
        case two:
          GLib.debug ("One");
          break;
        case three:
          GLib.debug ("Three");
          break;
        default:
          GLib.debug (val.to_string ());
          break;
      }
    }
    

    valac will generate:

    void foo (gint val) {
        static const gint one = 1;
        static const gint two = 2;
        static const gint three = 3;
        gint _tmp0_;
        _tmp0_ = val;
        switch (_tmp0_) {
            case one:
            {
                g_debug ("t.vala:8: One");
                break;
            }
            case two:
            {
                g_debug ("t.vala:11: One");
                break;
            }
            case three:
            {
                g_debug ("t.vala:14: Three");
                break;
            }
            default:
            {
                gint _tmp1_;
                gchar* _tmp2_ = NULL;
                gchar* _tmp3_;
                _tmp1_ = val;
                _tmp2_ = g_strdup_printf ("%i", _tmp1_);
                _tmp3_ = _tmp2_;
                g_debug ("t.vala:17: %s", _tmp3_);
                _g_free0 (_tmp3_);
                break;
            }
        }
    }
    

    gcc will say something like:

    t.vala.c:25:3: error: case label does not reduce to an integer constant
    t.vala.c:30:3: error: case label does not reduce to an integer constant
    t.vala.c:35:3: error: case label does not reduce to an integer constant
    

    Interestingly, clang is fine with it (valac --cc=clang ..., if you want to play with it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not using a layout-land, but do have drawable-land. The problem is, it
I've got a customer who told me that my program (simple user-land program, not
I'm not sure what it's called in the land of WinForms, but in web
How can i make the imageViews land beside eachother and not on top of
I seem to be stuck in Kafka-land, with a java.lang.String that I can't seem
Coming from the land of Perl, I can do something like the following to
In WCF land, you can specify a Namespace prefix for anything that has a
I'm trying to pass parameters from HTML-land to Flex-3 Flash-land, and can't seem to
99% of my time is in SQL Server land and so I'm not at
Well not being the best programmer in the land i thought i would ask

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.