View unanswered posts | View active topics It is currently Sun Apr 20, 2014 2:31 am






Reply to topic  [ 6 posts ] 
1.38: **Error**: 'return' statement required for exit 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 1.38: **Error**: 'return' statement required for exit
I lately am getting the following Error message (1.38 ) :
**Error**:'return' statement required for exit from non 'void' functions

with earlier versions there was not such a message, and I don't think this is intended...?

This the code:
Code:
 
int round(float f)
{
  if(f>=0) {return (int)(f + 0.5);}
  else     {return (int)(f - 0.5);}
}


With regular C compilers this is working -
how should I add an extra return here? and why?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Jul 25, 2008 3:50 pm, edited 1 time in total.



Sat Jul 12, 2008 8:41 am
Profile
Rookie

Joined: Wed Jun 25, 2008 6:07 pm
Posts: 46
Post 
Ford,

I tried your code (also on 1.38 Beta) and don't seem to be seeing the same problem as you.

In any case, it's pretty easy to guess what might be going on. Generally, compilers try to be smart and help you avoid things that are unintended. In this case, it appears that the compiler is not figuring out that the code will always return something, because all of the return statements are inside of conditional branches.

An easy way to fix this would be to remove the 'else' clause and just leave the last return statement outside of the 'if' altogether. That way, the compiler will have an easy time seeing that, no matter what, a value will always be returned:

Code:
int round(float f)
{
  if(f>=0) {return (int)(f + 0.5);}
  return (int)(f - 0.5);
}


By the way, are you sure that this is the only function in the code that could be causing the problem? As I mentioned earlier, your unmodified code appears to compile just fine for me (no errors).


Sun Jul 13, 2008 10:42 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
ok, fine, thx, this will work.
AvidProgrammer wrote:
By the way, are you sure that this is the only function in the code that could be causing the problem? As I mentioned earlier, your unmodified code appears to compile just fine for me (no errors).

no, there suddenly are more functions than just this one causing errors (with earlier RobotC version it has been working fine), but all error messages are due to the same "return error".
I really would appreciate "The Compiler" not always to break "his" head about my code optimization and not always to give an error message where there is no error! :evil:

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Mon Jul 14, 2008 5:02 am
Profile
Expert
User avatar

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Post 
Ford,

I, as the compiler expect you to be smarter than I am. Even if I try to figure out most frequent mistakes my users might have made, I am simply an algorithm, not even a complex one. Keep in mind that users of a software, just because of having outnumbered its creators, are *always* more inventive.

I, as the compiler generate pure clean and understandable bytecode from the character mess what you are typing just because you are far from fluent in raw machine code. Please be patient if I am unable to follow each and every branch of your thinking. The aforementioned example tries to affront my abilities. However, this error message is aimed to help those users who write more complex multi-branch conditional statements in which case it would require improportional efforts from me to evaluate the semantics whether the branches cover all possible input data or not.

Thanks for your understanding.

But, anyway, you are one of the thoughest beta tester I've ever seen :-)


Tue Jul 15, 2008 1:27 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
I tried it again, in other source codes, and the faulty error messages remain.

this is another case, where I NOW get the same error message, whereas with the 1.10 -1.22 I didn't:
Code:
char getc(){

  TButtons nBtn;
  nBtn = nNxtButtonPressed;      // check for button press

   switch (nBtn)     {
     case kLeftButton: {
       return 1;   break;     }

     case kRightButton: {
       return 2;   break;     }

     case kEnterButton: {
       return 3;   break;     }

     case kExitButton: {               
       return 4;   break;     }

     default: {
       return 0;   break;     }

   }
}
 

**Error**:'return' statement required for exit from non 'void' functions

There should be a way to switch off those foolish error messages.

I reported this to the bug tracker.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Jul 23, 2008 11:10 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.38: **Error**: 'return' statement required for exit
Dick Swan/Bug Tracker wrote:
This bug has already been resolved in the latest and soon to be released ROBOTC. It was a transitory bug that only existed for a few weeks and unfortunately you seem to have downloaded an interim release that had the problem.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Aug 20, 2008 12:56 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.