the comparisons of if clauses are still executed completely

Posted By: pegamode

the comparisons of if clauses are still executed completely - 06/13/10 11:17

Currently all comparisons of an if-clause are executed completely. I know that this behaviour was posted some time ago and it was announced that it should be changed within one of the following gs versions, but it hasn't been changed yet.

The following code still leads into an error:
Code:
void main() {
	ENTITY* ent = NULL;
	if (ent != NULL && is(ent, FLAG1)) {
		beep();
	}
}



Would be great if this could be changed. This behaviour leads into ugly if-else blocks with code duplication.

Regards,
Pegamode.
Posted By: Rei_Ayanami

Re: the comparisons of if clauses are still executed completely - 06/13/10 11:29

Seconded, that would be really nice to have...
Posted By: Vinous_Beret

Re: the comparisons of if clauses are still executed completely - 06/13/10 13:35

may be,but you can make you'r code even shorter:
Code:
void main() {
	ENTITY* ent = NULL;
	if (ent && is(ent, FLAG1)) {
		beep();
	}
}


Posted By: WretchedSid

Re: the comparisons of if clauses are still executed completely - 06/13/10 13:39

beret, this has nothing to do with the topic. In fact its just spam.

@Topic: I agree, this would be very nice.
Posted By: Vinous_Beret

Re: the comparisons of if clauses are still executed completely - 06/13/10 14:04

Quote:
beret, this has nothing to do with the topic. In fact its just spam.

and why is that??
besides,my last post was full of ironic! grin .
and iam definitely with this suggestion.
Posted By: Rei_Ayanami

Re: the comparisons of if clauses are still executed completely - 06/13/10 14:13

Because it is not about the shortness of code ...
Posted By: Vinous_Beret

Re: the comparisons of if clauses are still executed completely - 06/13/10 14:18

Quote:
Because it is not about the shortness of code ...

i know man,give me a break,it was only a JOKE... grin
"I forgot to put that SMILY up there"

@Sylar: if i want to post spam,i could only say"YES" or "NO".
Posted By: WretchedSid

Re: the comparisons of if clauses are still executed completely - 06/13/10 18:31

Originally Posted By: Vinous_Beret

@Sylar: if i want to post spam,i could only say"YES" or "NO".

What the fuck is wrong with you? Your post was clearly spam. And if it was really ironic, it wasn't even funny.

Posting Yes or No in such a thread makes clearly more sense, as the developer know how many users want or not want this feature. So they can decide how important a feature is.
Posted By: Vinous_Beret

Re: the comparisons of if clauses are still executed completely - 06/13/10 18:36

Quote:
What the fuck is wrong with you? Your post was clearly spam. And if it was really ironic, it wasn't even funny.


who the fuck are you to talk like this??
listen you FUCK,it's you'r fucking problem if you didn't laugh!
don't you ever use this language with me mad
Posted By: Rei_Ayanami

Re: the comparisons of if clauses are still executed completely - 06/13/10 18:38

Vinous, please, stop posting such things...

this was really not funny, no one has laughed wink

just a friendly reminder, not that any mod will ban you wink
Posted By: WretchedSid

Re: the comparisons of if clauses are still executed completely - 06/13/10 19:00

Originally Posted By: Vinous_Beret

who the fuck are you to talk like this??

Wayan Sidney Sastrosatomo Just. Nice to meet you.
Posted By: MMike

Re: the comparisons of if clauses are still executed completely - 06/13/10 19:16

Just calm down.. ok if he did spam, he probably was not aware of your reaction... was some joke ok. let it be.

and besides im still figuring out what the poster said with "This behaviour leads into ugly if-else blocks with code duplication."

code duplication what he means? and how come it executes?
was it supposed to stop on the first condition if ent!=NULL and not check the rest ..or is something different.. im just not getting.

I never though about such situations...
Posted By: Rei_Ayanami

Re: the comparisons of if clauses are still executed completely - 06/13/10 19:23

at the moment you need:

if(ent != NULL)
{
if(is(ent, SHOW))
{ [...] }
}

and we want:

if(ent != NULL /*if here this is already wrong, and the && follows, just stop*/ && is(ent, SHOW))
{
[..]
}
Posted By: Joey

Re: the comparisons of if clauses are still executed completely - 06/13/10 19:47

It's called short-circuit evaluation:
http://en.wikipedia.org/wiki/Short-circuit_evaluation
Posted By: MMike

Re: the comparisons of if clauses are still executed completely - 06/13/10 20:20

oh right i though that could be done already OOLOL, my bad.
That could explain some script behaviours not doing okay, and i though was my fault.
Posted By: Hummel

Re: the comparisons of if clauses are still executed completely - 06/13/10 20:44

I had the same prob some days ago, so I would appreciate this short-circuit evaluation thing.
Posted By: EvilSOB

Re: the comparisons of if clauses are still executed completely - 06/13/10 21:00

I too am STILL waiting on the short-circuit evaluation to be implemented...

I grow tired of using work-arounds like
Code:
void main() {
	ENTITY* ent = NULL;
	if(ent!=NULL) if(is(ent, FLAG1))
	{
		beep();
	}
}

because there is some you just cant do...
Posted By: Rackscha

Re: the comparisons of if clauses are still executed completely - 06/13/10 21:04

Would like to have it too.
Always need an extra IF-block for checking if an entity is valid v.v(tooo many brackets)

Greets
Rackscha
Posted By: Superku

Re: the comparisons of if clauses are still executed completely - 06/13/10 23:41

I hope it's possible to change it anymore because I would really like to see "short-circuit evaluation", too.
Posted By: Joozey

Re: the comparisons of if clauses are still executed completely - 06/14/10 08:52

Seconded.
Posted By: jcl

Re: the comparisons of if clauses are still executed completely - 06/14/10 08:56

This is planned, but with low priority as it does not make your code worse or longer. You just need to be aware of the fact that you need 'if' instead of '&&' when you want to early abort a comparison. See:

http://manual.3dgamestudio.net/litec_c.htm
Posted By: pegamode

Re: the comparisons of if clauses are still executed completely - 06/14/10 09:37

But in some cases the code can't be replaced by just using "if" instead of "&&":

Code:
ENTITY* ent = NULL;
if(ent != NULL) {
  if (is(ent, FLAG1)) {
    ... do something ...				
  } else {
    ... do something else ...
  }
} else {			
  ... do something else (the same else as above) ...
}



For this code I need either code duplication or I have to set a boolean and check this to decide which code has to be executed.

But it could be like this:

Code:
ENTITY* ent = NULL;
if(ent != NULL && is(ent, FLAG1)) {
  ... do something ...				
} else {
  ... do something else ...
}



So it makes the code worse and longer.

Regards,
Pegamode.
Posted By: jcl

Re: the comparisons of if clauses are still executed completely - 06/14/10 10:10

Ok, in that case you're right. We'll implement early comparison abort when the compiler is improved the next time.
Posted By: pegamode

Re: the comparisons of if clauses are still executed completely - 06/14/10 10:19

Ok. Thanks.
Posted By: FBL

Re: the comparisons of if clauses are still executed completely - 06/14/10 17:17

When is "next time"? laugh
Posted By: pegamode

Re: the comparisons of if clauses are still executed completely - 02/23/11 18:19

I just want remind you on this topic and second the question "when is next time" ???

I think that a nowadays compiler should handle something like that properly.

Regards,
Pegamode.
Posted By: Superku

Re: the comparisons of if clauses are still executed completely - 02/23/11 18:43

I'm waiting eagerly for this compiler change, too.
Posted By: FBL

Re: the comparisons of if clauses are still executed completely - 02/23/11 20:15

Oh yes!
Posted By: Widi

Re: the comparisons of if clauses are still executed completely - 02/23/11 20:42

Me too ( maybee a present for my birthday today wink )
Posted By: Uhrwerk

Re: the comparisons of if clauses are still executed completely - 02/23/11 22:21

Me too. And maybe while you're at it implement the functions with a variable argument number, which has been on the forecast page for ages..? tongue
Posted By: Superku

Re: the comparisons of if clauses are still executed completely - 02/23/11 22:30

Quote:
functions with a variable argument number

Works fine for me (or am I missing sth?) :
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////


var add(var x, var y, var z) {
	return (x+y+z);
}

var add(var x, var y) {
	return (x+y);
}

void main() {
	video_screen = 0;
	printf("\n%d",(int)add(1,2));
	printf("\n%d",(int)add(1,2,3));
}


Posted By: WretchedSid

Re: the comparisons of if clauses are still executed completely - 02/23/11 22:34

The problem is that variadic functions don't work. Your example is just overloarding, but what Uhrwerk means is something like this:

Code:
void foo(char *format, ...)
{
   va_list args;
   va_start(args, format);

   // Do something with the format string

   va_end(args);
}



Btw, declaring functions which take variable arguments is already supported, but va_list, va_start, va_arg, va_end and va_copy is missing.
© 2024 lite-C Forums