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:18
Read: times


 
#181201 - const function parameter declaration
Hi

We are using 8052 in our project. We are using 128K EPROM, and using Code Banking of Keil with 2 code banks. We are cross-checking our code using PC-Lint ver 9.0f.

We increased the warning level by making changes to the co-kc51.lnt file. We added -w4 and ran PC-Lint. Then, PC-Lint generated the following Elective Notes:


#include<Reg52.h>
bit trans_ready;
void sendDataToSerialPort(unsigned char i)
{
	trans_ready = 0;	/* Clearing the data transmitted flag */
	SBUF = i;		/* Sending data to Serial Buffer. This is Line 38 */
	while(!trans_ready)	/* Waiting till this flag is set in Serial Routine */
}

Note 952: Parameter 'i' (line 38) could be declared const.

There are nearly 150 functions for which PC-Lint suggested this. All function parameters are non-pointers.

There is no change in the compiled data after adding 'const' as shown:

void sendDataToSerialPort(const unsigned char i)
{
	trans_ready = 0;	/* Clearing the data transmitted flag */
	SBUF = i;		/* Sending data to Serial Buffer. This is Line 38 */
	while(!trans_ready)	/* Waiting till this flag is set in Serial Routine */
}
 

Q1. What will be the impact on the performance by declaring this function parameter as 'const'?

The extern declaration is:

extern void sendDataToSerialPort(unsigned char);

Q2. Is it required to use const in this function prototype declaration also?

Please suggest.

thanks in advance.


List of 3 messages in thread
TopicAuthorDate
const function parameter declaration            01/01/70 00:00      
   lint can be too noisy if you ask it to            01/01/70 00:00      
   const correctness            01/01/70 00:00      

Back to Subject List