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 8996881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:48:49+00:00 2026-06-15T23:48:49+00:00

I cant get enum this to work properly on Windows. While compiling on linux

  • 0

I cant get enum this to work properly on Windows. While compiling on linux it returns expected value, but on windows it returns some random number.

typedef enum wezly {
    elektrownie1,
    konwencjonalne1,
    niekonwencjonalne1,
    weglowa1,
    jadrowa1,
    sloneczna1,
    wiatrowa1,
    geotermiczna1,
    gazowa1,
    wodna1,
    maremotoryczna1,
    maretermiczna1
};

wezly wybor_wezla(string opcja)
{
    string bb;
    bb = opcja;

    if ((bb.compare("[elektrownie]")==0)||(bb.compare("[ELEKTROWNIE]")==0))
        return elektrownie1;
    else if ((bb.compare("[konwencjonalne]")==0)||(bb.compare("[KONWENCJONALNE]")==0))
        return konwencjonalne1;
    else if ((bb.compare("[gazowa]")==0)||(bb.compare("[GAZOWA]")==0))
        return gazowa1;
    else if ((bb.compare("[wodna]")==0)||(bb.compare("[WODNA]")==0))
        return wodna1;
    // (and so on...)
}

int main()
{

    cout << wybor_wezla("[gazowa]");
}

When on linux i get 7, on windows its some random number….

Why can that be ?

  • 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-15T23:48:50+00:00Added an answer on June 15, 2026 at 11:48 pm

    Your code is missing a final else clause:

    wezly wybor_wezla(string opcja)
    {
        if(...)
            return ...;
        else if(...)
            return ...;
        else if(...)
            return ...;
        // No final else!
    }
    

    When none of the if clauses are true, it falls off the end of the function without returning a value, which is Undefined Behavior. In this case, it’s returning a garbage value, but worse stuff could happen.

    Your first action should be to add a final else clause. This can return a default value, an error code, throw an exception, abort(), etc., but it cannot do nothing. If you know the value has to be one of a limited set of things, you could change the final else if into just an else and assume that if it’s not the first N-1 things, it’s the Nth thing.

    Once you’ve done that, you need to figure out why your data isn’t falling into one of the expected cases and fix that.

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

Sidebar

Related Questions

I'm probably doing something realy stupid but I cant get this to work: var
Cant get this script to work with my menu really have tried everything any
Probably I cant get more dumb, but seriously this is the first time I
When i run this code i get errors sometimes but not allways. I cant
I cant get jquery's date picker to work on my page. I have a
I'm writing an enum value with an XmlWriter, and it look something like this
This seems like it should be prettty easy - but I just can't get
For some odd reason, I can't get qi::as_string[] to work with repeat()[] . Parsing
I cant get a PHP file to send correct headers at my WAMP server.
Can someone explain why i cant get the desired delay between each request? They

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.