format ‘%lu’ expects argument of type ‘long unsigned int’……

Printing problem, this kind of error report means that the output format does not match the variable. First, I will quote the previous article to briefly explain the difference between %d %ld %lld, %u %lu %llu, %x %lx %llx icon-default.png?t=N4P3https:/ /www.cnblogs.com/KingZhan/p/16425831.html



首先说明,不同平台下不一样!    下面说的是arm 32位平台的

 
%d 输出有符号32位的

%ld 输出有符号32位的

%lld 输出有符号64位的
 

%u 输出无符号32位的

%lu 输出无符号32位的

%llu 输出无符号64位的

 
%x 输出32位16进制数的

%lx 输出32位16进制数的

%llx 输出64位16进制数的

When we usually involve these printouts in large projects, we often need to match different targets, so there is a macro definition format that automatically matches different targets:

-------------------------------------------------
//类型定义
typedef unsigned char   uint8_t;
typedef unsigned short  uint16_t;
typedef unsigned int    uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned long   uintptr_t;

typedef signed char     int8_t;
typedef short           int16_t;
typedef int             int32_t;
typedef long long       int64_t;
typedef long            intptr_t;

-------------------------------------------------
//打印前缀
#define PRId32 "d"
#define PRIu32 "u"
#define PRIx32 "x"
#define PRIX32 "X"
#define PRId64 "lld"
#define PRIu64 "llu"
#define PRIx64 "llx"
#define PRIX64 "llX"
-------------------------------------------------
//依据不同平台,定义target

# define TARGET_LONG_BITS             64
# define TARGET_LONG_BITS             32

#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)


#if TARGET_LONG_SIZE == 4        

    typedef int32_t target_long;
    typedef uint32_t target_ulong;

    #define TARGET_FMT_lx "%08x"
    #define TARGET_FMT_ld "%d"
    #define TARGET_FMT_lu "%u"

#elif TARGET_LONG_SIZE == 8

    typedef int64_t target_long;
    typedef uint64_t target_ulong;

    #define TARGET_FMT_lx "%016" PRIx64
    #define TARGET_FMT_ld "%" PRId64
    #define TARGET_FMT_lu "%" PRIu64
#else
    #error TARGET_LONG_SIZE undefined
#endif

In this way, when we print specifically, we can directly spell it with the corresponding statement:

printf("nip=0x"TARGET_FMT_lx, cpu->env.nip);

fprintf(stderr, "nip=0x"TARGET_FMT_lx, cpu->env.nip);                                                                                                                                                  

error_report("nip=0x"TARGET_FMT_lx, cpu->env.nip)

 

Guess you like

Origin blog.csdn.net/jcf147/article/details/131068242