[No] suport for returns on functions not only in the end

Moderator: Developers

suport for returns on functions not only in the end

Postby ibm5155 » Sat Jun 16, 2012 4:38 pm

Well i was wandering if you´d mind inplementing a return that is not required a return only on the end of a function, example

this is a method that i don´t like to use
Code: Select allExpand view
function int ibm_negativo(int a)
{
  int x;
   if (a<0)
      x=1;
   else x=0;
    return x;
}


here is how it should be (like in c)
Code: Select allExpand view
function int ibm_negativo(int a)
{
  int x;
   if (a<0)
      return 1;
   else return 0;
}


but in doom builder i can´t compile without a return on the end :( , so, i think this could help others with functions too, because it doen´t require a little part of memory for cearing x for acumulate just 1 or 0, and even the performance could be helped (if enter on the first if, then he return 1 and stop the function, not testing the rest...)

I´m not going to talk it´s a easy thing to do, but if acs similar to c, i really don´t thing it´s a difficult thing to do, just a little modify on the acs compiler and voala \o/
User avatar
ibm5155
 
Joined: 20 Jul 2011

Re: suport for returns on functions not only in the end

Postby Isle » Sat Jun 16, 2012 5:26 pm

you could just use the second example and get rid of the else. when it hits a return it skips the rest of the function.
User avatar
Isle
WadAuthor 4 L1F3
 
Joined: 21 Nov 2003
Location: Arizona, USA

Re: suport for returns on functions not only in the end

Postby Graf Zahl » Sat Jun 16, 2012 6:17 pm

ibm5155 wrote:i really don´t thing it´s a difficult thing to do, just a little modify on the acs compiler and voala \o/


The problem is, that the ACC compiler is not sanely programmed. One can only hack it this far and no further.
I'll leave the decision to Randy though.
User avatar
Graf Zahl
 
Joined: 19 Jul 2003
Location: Germany

Re: suport for returns on functions not only in the end

Postby Apothem » Sat Jun 16, 2012 6:38 pm

but the else statement in that code is basically what would happen even if you left the else out. When you use return it terminates the function anyway. I fail to see the point of this :?
User avatar
Apothem
ACS scripting makes my head go BooM!
 
Joined: 29 Nov 2003
Location: Performing open heart surgery on an ACS compiler.

Re: suport for returns on functions not only in the end

Postby randi » Sat Jun 16, 2012 8:38 pm

ACC doesn't maintain enough state to know that both paths through the if return values, so yes it is a difficult thing to do (relatively speaking, anyway). As Isle said, in this particular case, you can just get rid of the else, and the result will be a working function that does the same thing.
User avatar
randi
Site Admin
 
Joined: 09 Jul 2003

Re: suport for returns on functions not only in the end

Postby ibm5155 » Sun Jun 17, 2012 9:29 am

:o i didn´t try that method, thanks randi ^^
User avatar
ibm5155
 
Joined: 20 Jul 2011


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: Bing [Bot] and 1 guest