Using in user programs, or in driver module code…does it matter?

前端 未结 2 1469
栀梦
栀梦 2020-12-30 07:54

I\'m developing a device driver module and associated user libraries to handle the ioctl() calls. The library takes the pertinent info and puts it into a struc

2条回答
  •  盖世英雄少女心
    2020-12-30 08:45

    Fixed length integers in the Linux kernel

    The Linux kernel already has fixed length integers which might interest you. In v4.9 under include/asm-generic/int-ll64.h:

    typedef signed char s8;
    typedef unsigned char u8;
    
    typedef signed short s16;
    typedef unsigned short u16;
    
    typedef signed int s32;
    typedef unsigned int u32;
    
    typedef signed long long s64;
    typedef unsigned long long u64;
    

    LDD3 has a chapter about data sizes as well: https://static.lwn.net/images/pdf/LDD3/ch11.pdf

    LDD3 mentions there that the best printk strategy is to cast to just cast to the largest integer possible with correct signedness: %lld or %llu. %ju appears unavailable under the printk formatting centerpiece lib/linux/vsprintf.c.

提交回复
热议问题