Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/21/11 11:20
Read: times


 
#181202 - const function parameter declaration -2
There is one more issue with const function parameters as shown:


#include<Reg52.h>
unsigned char charector(const unsigned char mychar)
{
	if(mychar>12)					
		return ' ';
	switch(mychar)
	{
		case 11:					
			return '*';
		case 12:					
			return '#';
		case 10:					
			mychar=0;
		default:					
			return (mychar+0x30);
	}
}

 


If we make 'mychar' declaration const, Keil is generating the errors:
error C183: unmodifiable lvalue
error C187: not an lvalue

This is because the parameter is being modified inside the function, and declaring it const will definitely raise an error by the Keil compiler.

But, if the same change is being made to the function prototype as shown, Keil is compiling without any error:

extern unsigned char charector(const unsigned char);

! The function prototype logically reflects the function definition. But, changes being made to the function prototypes in this manner is being compiled without errors. Is this a problem with the Keil compiler, or is there no effect of the prototype on the original function definition?

Even PC-Lint is not issuing any error or warning on this.

Q. Please suggest how to come out of this error.

thanks in advance.


List of 5 messages in thread
TopicAuthorDate
const function parameter declaration -2            01/01/70 00:00      
   call by value            01/01/70 00:00      
   Overloaded function            01/01/70 00:00      
      No overloading in C            01/01/70 00:00      
   case 10: return 0x30;            01/01/70 00:00      

Back to Subject List