- 论坛徽章:
- 0
|
谁能去掉这个警告信息. 'TEXT'的警告
她是可以工作的。不过要看你的编译器。如果是16bit系统的则' '中的字符只能是2个字符。如果是32bit ' '中的字符就是可以4个字符了。你可以在bc31和dev-C++种尝试一下。在bc31中'TX'没有任何警告信息。但是在dev-C++中会有警告信息。下面是我的测试程序和结果。
- 源程序
- #include <stdio.h>;
- unsigned long test_function( unsigned long type )
- {
- printf("test_function()\n");
- printf("type(hex) = %x \n", type );
- printf("type(char) = %c %c %c %c\n", (type>;>;24)&0xff, (type>;>;16)&0xff, (type>;>;8)&0xff, (type)&0xff );
- return type;
- }
- int main( int argn, char *argv[] )
- {
- unsigned long type;
- printf("before\n");
- type = 'TEXT'; /* 如果在16bit系统中则只能是 'TE' */
- printf("type(hex) = %x \n", type );
- printf("type(char) = %c %c %c %c\n", (char)(type>;>;24)&0xff, (char)(type>;>;16)&0xff, (char)(type>;>;8)&0xff, (char)(type)&0xff );
- type = 0;
- type = test_function( 'TEXT' );
- printf("after\n");
- printf("type(hex) = %x \n", type );
- printf("type(char) = %c %c %c %c\n", (type>;>;24)&0xff, (type>;>;16)&0xff, (type>;>;8)&0xff, (type)&0xff );
- return;
- }
- 执行结果
- before
- type(hex) = 54455854
- type(char) = T E X T
- test_function()
- type(hex) = 54455854
- type(char) = T E X T
- after
- type(hex) = 54455854
- type(char) = T E X T
- 在16bit 方式下运行由于printf()中的%c会出现0,达因结果会不完整。
- 谁有办法通过变换类型的方式消除那个警告信息。
复制代码 |
|