Results 1 to 6 of 6

Thread: Strange behavior on Wine/Linux

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2018
    Location
    Krähental
    Posts
    64

    Strange behavior on Wine/Linux

    Code:
    double d = 0;
    string s = "";  // Empty string
    
    if (double.TryParse(s, out d) == true)
    {
        if (d.ToString() == "")
        {
            MessageBox.Show("Is Empty String");
        }
    }
    The code seems quite straight forward. The string s is empty so the tryparse should fail. On Windows it does and the messagebox is never shown.

    But in an c# application in Wine the tryparse is true and, somehow, d is empty. (ie d is not zero, not even null. simply empty) and the messagebox shows.

    How is that?

    Any other strange things I need to be aware of while making my app compatible with Wine?

    Thanks

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Strange behavior on Wine/Linux

    When you say d is "empty" what exactly do you mean? A variable of type double can't be empty, it is a value type and it should always contain something!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2018
    Location
    Krähental
    Posts
    64

    Re: Strange behavior on Wine/Linux

    Quote Originally Posted by PlausiblyDamp View Post
    When you say d is "empty" what exactly do you mean? A variable of type double can't be empty, it is a value type and it should always contain something!
    Exactly. I agree. It "Must" always have a value. That's the reason for my question.

    Did you look at my code? Look at the line if (d.ToString() == "") That MessageBox should never show because d can not be empty. But when running on Wine/Linux the messagebox always shows if s is an empty string.

    Remember, I'm talking about a c# (Net4) application running in 'Wine' on Linux. On Windows it behaves as expected. d is never empty. But on Linux it is empty.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2018
    Location
    Krähental
    Posts
    64

    Re: Strange behavior on Wine/Linux

    What I'm saying is that double.TryParse("", out d) (empty string) should return false. So that next line should never execute.

    On Windows the tryparse correctly returns false. But running that code on Wine/Linux that TryParse returns true even though we're tryparsing an empty string into a double. That's the first bug.
    But then, as you said, d can not be empty so the result of d.ToString() should not be empty. But it is.

  5. #5
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Strange behavior on Wine/Linux

    I genuinely would have no idea where to go from there, if something as fundamental as double.TryParse and even a double itself isn't working correctly then I wouldn't have much faith in anything working right.

    Are there other places in the app where this works or is this the only place you are using this code?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2018
    Location
    Krähental
    Posts
    64

    Re: Strange behavior on Wine/Linux

    Quote Originally Posted by PlausiblyDamp View Post
    I genuinely would have no idea where to go from there, if something as fundamental as double.TryParse and even a double itself isn't working correctly
    then I wouldn't have much faith in anything working right.

    Are there other places in the app where this works or is this the only place you are using this code?
    I have quite a large database application that currently only intended for MS Windows. I was just curious about how much work would be needed to make it work in Wine on Linux.
    I was surprised to find the application works quite well. I had to remove some assumptions about Windows Fonts and I couldn't get oleDb/Jet working but the app can use MySQL anyway. Apart from that, it seems to work fine and very fast. Almost as fast as on a proper windows machine.

    But I make use of a c# function that converts a string to a number. Similar to the VisualBasic Val() function.


    Code:
    public static double Val(string s)
    {
        if (s == "") return 0;  // This line is only necessary when running in Wine/Linux
    
        double d = 0;
        if (double.TryParse(s, out d) == true) 
            return d; 
        else
            return 0;   
    
    }
    But for Wine Linux I had to add that first line that checks for an empty string otherwise it goes wrong.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width