请教C语言强制类型转换的一个问题
有这样一个函数void func(unsigned char a)
{
(void) a;
}
请问里面的(void)是什么意思?
实在搞不懂啊,求教了:) 只是一个类型为空的变量,应该是占用一个字节的空间。。好像是这样的。 (void *)是有的,void型的变量真的没见过 看看那个编译器会放过你再说 变量被访问了,但什么都没做。
通常用来欺骗编译器。
void func(unsigned char a)
{
//变量a没有被使用,有些编译器会有警告
}
void func(unsigned char a)
{
(void) a; //变量a什么都不做,但表示被访问过了,编译器不会有警告
}
void func(volatile unsigned char a)
{
(void) a; //读一次变量a,但读出来的值不做任何处理。
} voidx真是高手啊,学习了,谢谢
贴出问题的出处,给大家参考
eMBErrorCode
eMBRTUInit( UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
{
eMBErrorCode eStatus = MB_ENOERR;
ULONG usTimerT35_50us;
( void )ucSlaveAddress;
ENTER_CRITICAL_SECTION();
/* Modbus RTU uses 8 Databits. */
if( xMBPortSerialInit( ucPort, ulBaudRate, 8, eParity ) != TRUE )
{
eStatus = MB_EPORTERR;
}
else
{
/* If baudrate > 19200 then we should use the fixed timer values
* t35 = 1750us. Otherwise t35 must be 3.5 times the character time.
*/
if( ulBaudRate > 19200 )
{
usTimerT35_50us = 35; /* 1800us. */
}
else
{
/* The timer reload value for a character is given by:
*
* ChTimeValue = Ticks_per_1s / ( Baudrate / 11 )
* = 11 * Ticks_per_1s / Baudrate
* = 220000 / Baudrate
* The reload for t3.5 is 1.5 times this value and similary
* for t3.5.
*/
usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate );
}
if( xMBPortTimersInit( ( USHORT ) usTimerT35_50us ) != TRUE )
{
eStatus = MB_EPORTERR;
}
}
EXIT_CRITICAL_SECTION();
return eStatus;
}
ucSlaveAddress确实没有用到:) 再请教voidx一下,如果(void)func();是什么意思呢 程序是这样的:
if( xMBPortEventGet( &eEvent ) == TRUE )
{
switch ( eEvent )
{
case EV_READY:
break;
case EV_FRAME_RECEIVED:
eStatus = peMBFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
if( eStatus == MB_ENOERR )
{
/* Check if the frame is for us. If not ignore the frame. */
if( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) )
{
( void )xMBPortEventPost( EV_EXECUTE );
}
}
break;
} 操作的如果是寄存器,可能有特殊作用。有些特殊寄存器被读取时,会清/置某些标志位 5楼高手也 曾强制转换过函数返回值,变量还真不知道。5楼高手,学习! 学习一下....
页:
[1]