/**
* 函数: void test_printk(void)
* 功能: printk 可变参数的传递
* 1) 根据各自的类型传递进入,如果需要,必须强制类型转换.
* 2) 整型最大宽度: 4字节,如果传入 8字节的 long long 类型,注定后面跟参数出问题.
* 3) %2.2X 之类的,只是决定了输出的格式,对数据存储,解释没任何影响.
*
* 总之: printk不支持超过4字节的整型;强制类型转换是必要的.
* 下面函数输出结果:
[45683.730855] ======= test_printk =========
[45683.730896] my_test_var1=AABBCCDD test0=12345678 : wrong!
[45683.730918] (int)my_test2_var=AABBCCDD test0=000003E8 : correct!
[45683.730954] DD CC BB AA 78 56 34 12
[45683.730984] ======= test_printk ok=========
*/
void test_printk(void)
{
int i;
unsigned char *pByte;
long long my_test_var; //如果是 int my_test_var; 或 char my_test_var; 就没事啦~~~
int test0;
printk("\n\n======= test_printk ========= ");
test0=1000;
my_test_var=0x12345678AABBCCDD;
printk("\n my_test_var1=%X test0=%8.8X : wrong!",my_test_var, test0) ;
printk("\n(int)my_test2_var=%X test0=%8.8X : correct!\n",(int)my_test_var, test0) ;
pByte=&my_test_var;
for(i=0;i< sizeof(my_test_var);i++)
{
printk(" %2.2X ", *pByte);
pByte++;
}
printk("\n======= test_printk ok=========\n\n");
}
阅读(629) | 评论(0) | 转发(0) |