Re: [Vala] Why is 77 greater than 4294967295?



 
    > On Friday, 23 November 2018, 06:15:37 GMT, Heiher <root heiher info> wrote:  >Wow! Why the comparison 
behavior of a signed long with an unsigned int
isn't same as C/C++ in Vala?
if (i > uint.MAX)  => if (_tmp6_ > (G_MAXUINT))

If you wish to look in to this further then I understand Vala follows the 'usualarithmetic conversion' rules, 
similar to C. This is where the rank details forsimple types are used. See 
https://wiki.gnome.org/Projects/Vala/LegacyBindings#Simple_Type_StructsHere a long is rank 8 and uint is rank 
7 so there is an implicit cast to long:
if (_tmp6_ > ((glong) G_MAXUINT)) {}
As Michele Dionisio points out earlier this a problem on an architecture wherea long is the same size as an 
int. On my PC I don't have that problem, althoughpersonally I think there should be an --explicit-cast-only 
option at some pointfor Vala.

What is also interesting is the use of _tmp6_ after these two recent 
commits:https://gitlab.gnome.org/GNOME/vala/commit/32ffc862417be39d42a1b8eeb3d0748b3e138affhttps://gitlab.gnome.org/GNOME/vala/commit/e701142da4601ece5ca71cc4484728b08969c74eCompiling
 now from master shows the temp variable is no longer generated. The output 
from:/home/vala_from_master/bin/valac test.vala --ccode --target-glib 2.40is:
/* test.c generated by valac 0.42.1.163-2a1c9, the Vala compiler
 * generated from test.vala, do not modify */

#include <glib.h>
#include <stdio.h>

void _vala_main (void);

void
_vala_main (void)
{
    glong i = 0L;
    FILE* _tmp0_;
    FILE* _tmp1_;
    FILE* _tmp3_;
    i = (glong) 77;
    _tmp0_ = stdout;
    fprintf (_tmp0_, "%ld\n", i);
    _tmp1_ = stdout;
    fprintf (_tmp1_, "%u\n", 0);
    if (i < ((glong) 0)) {
        FILE* _tmp2_;
        _tmp2_ = stdout;
        fprintf (_tmp2_, "Never made it here.\n");
    }
    _tmp3_ = stdout;
    fprintf (_tmp3_, "%u\n", G_MAXUINT);
    if (i > ((glong) G_MAXUINT)) {
        FILE* _tmp4_;
        _tmp4_ = stdout;
        fprintf (_tmp4_, "Why am I here.\n");
    }
}

int
main (int argc,
      char ** argv)
{
    _vala_main ();
    return 0;
}

Some may also notice the #include <glib-object.h> has gone. This is 
after:https://gitlab.gnome.org/GNOME/vala/commit/2ceaa53017b933a2856b878d436d2ae040b0f9b6
Firstly, many thanks to ricotz for the continued work on improving the Vala compiler. Secondlythis is a 
significant step to allowing Vala to compile code using only the standard C library, withoutneeding GLib. 
Potentially this could be done by compiling with --nostdpkg and using a basic-types-libc.vapi binding.

If anyone is interested in this aspect of Vala then try out master. Report any edge case bugs youfind and 
possibly have a go at hacking on the compiler. Some relevant issues are:
https://gitlab.gnome.org/GNOME/vala/issues/703https://gitlab.gnome.org/GNOME/vala/issues/624https://gitlab.gnome.org/GNOME/vala/issues/623
Have fun!
Al






  


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]