Question about IF

Posted By: Logitek

Question about IF - 11/23/15 19:31

Hello, I have an interesting question about the IF command.

For example:

If (a == 1 && b == 1 && c == 1)
{Do something}

Does the engine now proof each var, also if a is not 1?
I mean: Does the engine break the line and is looking for the next command or does it also check b and c? Also if we already know that a is not 1 and it can not be end in true anymore?

It is interesting for scripts with a lot of IF commands.
I think it is breaking the line, right?






Posted By: WretchedSid

Re: Question about IF - 11/23/15 19:37

It should not check the following statements after encountering a false one in this situation, but it still does. It's easy to proof:

Code:
ENTITY *ent = NULL;

if(ent && ent->x == 0)



This is valid and every normal C compiler won't try to evaluate the second statement, however in Lite-C, you can enjoy a beautiful crash. It's documented somewhere in the manual.
Posted By: Superku

Re: Question about IF - 11/23/15 19:52

This has been asked for several times on this forum already, and I think it's been on the infamous "list" for a compiler revamp for a few years now.
It would make a lot of stuff like Sid's example or array access easier and nicer.
Posted By: Anonymous

Re: Question about IF - 11/23/15 20:00

Quote:
If (a == 1 && b == 1 && c == 1)


if(a+b+c == 3)


Lol just thought I write something.
Mal
Posted By: Superku

Re: Question about IF - 11/23/15 20:17

That's a different/ not equivalent if statement though, for example for a = 3, b = 0 = c. wink
Posted By: FBL

Re: Question about IF - 11/23/15 20:18

early abortion (if(ent && ent->x == 0) example) is not supported by the Lite-C compiler and it's one of the most annoying limitations of Lite-C...
This means, all statements of the if are always evaluated. If you want it different, you have to go with nested ifs... jippijajey
Posted By: Logitek

Re: Question about IF - 11/23/15 20:50

Okay, interesting.


if (a==1)
{
If (b==1)
{
If (c==1)
{ do something }
}
}

And this example would abort after line 1 if a is not 1, right?
Posted By: jcl

Re: Question about IF - 11/24/15 10:21

Yes. I admit that this is a clumsy way, but that's how the compiler works - and to change this to the normal C compiler standard is a major act, unfortunately.
Posted By: Logitek

Re: Question about IF - 11/30/15 11:30

Hello.

How was it with the old c-script and the interpreter? The same way?
Posted By: Superku

Re: Question about IF - 11/30/15 13:17

Originally Posted By: jcl
Yes. I admit that this is a clumsy way, but that's how the compiler works - and to change this to the normal C compiler standard is a major act, unfortunately.

That's a pity but okay...
Posted By: jcl

Re: Question about IF - 12/01/15 10:17

Yes, same way with the old C-Script.
Posted By: Logitek

Re: Question about IF - 12/01/15 11:20

Thank you for the information!
© 2024 lite-C Forums