ENIGMA Forums

General fluff => General ENIGMA => Topic started by: Goombert on October 23, 2013, 04:28:24 AM

Title: ISO C99 Scalar Boolean Casting
Post by: Goombert on October 23, 2013, 04:28:24 AM
Well it appears we need to get on this. Basically I don't why Josh, you think that negative numbers are not boolean true, according to C99 ISO any integer value that does not equate to 0 is boolean true when cast.
http://stackoverflow.com/questions/4254318/are-negative-boolean-values-defined

Quote
ยง 6.3.1.2
When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.

So my question is basically this, what is wrong with our compiler that it is not working for collision functions that return -4 (noone) ???

Also, Studio does continue this behavior from the earlier versions of Game Maker as I have tested the following code which does show a message box with -4 in it.
Code: (EDL) [Select]
if (noone) {
show_message(string(noone));
}

I only began questioning this after looking at the following code from a tutorial game that comes with Stupido I got running now that I added event inheritance.
Code: (EDL) [Select]
first_instance = collision_line(x, y, xx, yy, obj_Col_Parent, true, true);

if first_instance != noone
    {
    dx = xx - x;
    dy = yy - y;
    while (abs(dx) >= 1 || abs(dy) >= 1)
        {
        dx /= 2;
        dy /= 2;
        instance = collision_line(x, y, xx - dx, yy - dy, obj_Col_Parent, true, true);
        if (instance != noone)
I only got curious because for some reason they took the extra precaution with the result of the collision functions. I am really failing to see something here.

Here is a picture of the game...
(http://oi44.tinypic.com/nohdmb.jpg)

I just ran this same test in ENIGMA and I get the expected results. So what exactly is the issue with the collision functions again and why they don't behavior properly as the result of negative values?
Title: Re: ISO C99 Scalar Boolean Casting
Post by: Ideka on October 23, 2013, 04:44:54 AM
The problem is this:
In GM, a value of -4 is false, as are all other values less than 0.5. In ENIGMA, only a value of 0 is false.

If noone evaluates to true in Studio, then they changed it. Its false in GM8 and lower.
Title: Re: ISO C99 Scalar Boolean Casting
Post by: Goombert on October 23, 2013, 04:47:31 AM
Ohhhhhhhhh so the problem is that we actually do follow the standard, and apparantly Studio does now as well, so my initial assumptions were correct, thank you Ideka, then I guess we can just keep everything like this since Stupido has finally caught up to the correct behaviour, I need to forward this post tomorrow for Josh to read, thanks  (Y)
Title: Re: ISO C99 Scalar Boolean Casting
Post by: Ideka on October 23, 2013, 04:52:14 AM
You're welcome.

And actually, I think Josh said he was going to create a new type for this to preserve backwards compatibility.
Title: Re: ISO C99 Scalar Boolean Casting
Post by: Goombert on October 23, 2013, 04:55:30 AM
He'll need to make it a setting then, could be just the same as the others in ENIGMA settings...

Inherit boolean scalar: GML ( )   ISO C99 (*)

I'd rather have the ISO standard set as the default, I may actually change a few of his settings there too because I want literals such as ++/-- by default to be ISO C as well because Stupido has those by default too, and we've had them forever I don't want people complaining we don't have it yet or something.

It would basically look like this, keep in mind I am also working on adding in some settings for the other things I have implemented.
(http://oi44.tinypic.com/2metobk.jpg)