CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Compiler doesn’t catch the error. Bug?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Compiler doesn’t catch the error. Bug?
PostPosted: Tue Mar 25, 2008 4:04 pm     Reply with quote

Colleagues,

I’m not getting a compile-time error, when I expect it. This could be a bug. Take a look. I’ve declared a function to return int8, but commented out the return statement. Later, I call the function and compare the returned value to a constant.

Code:

int8
spi_read_only()
{
   int8 i;
   int8 iRet;        // return value received from SPI
   
   output_high(SDO); // the host will receive 0xFF.
   for (i=0;i<8;i++)
   {
      output_low(SCLK);
      shift_left(iRet, 1, input(SDI));
      output_high(SCLK);
   }   
//   return iRet;  // this should provoke a compile-time error
}

int8     
mmc_send_command(...)
{
   ...
   while ( (spi_read_only() != 0xFF) && iTimeoutCount < iMAX_TIMEOUT_COUNT)
   {
   // a comparison to an output of a  function that doesn’t return anything should provoke another compile-time error



PCWH 3.240
16F690
_________________
Read the label, before opening a can of worms.
Ttelmah
Guest







PostPosted: Tue Mar 25, 2008 4:11 pm     Reply with quote

No, this is standard in C.
This is why (for example), the 'Main' function, in a standard C program (not CCS), which normally returns a status byte to the OS, can be omitted.
Falling off the end of a function, or having a return with no value, is defined to return 'garbage' in the C reference manual, but is not illegal.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group