我有uint8_t orig[ETH_ALEN];
如何使用__printf(3, 4)打印它?
它被定义为#define __printf(a, b) __attribute__((format(printf, a, b)))
Orig应该是以太网硬件地址。
发布于 2013-01-16 20:56:37
您需要构造一个合适的格式字符串。printf()函数无法一次性打印数组,因此需要拆分它并打印每个uint8_t
__printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
orig[0] & 0xff, orig[1] & 0xff, orig[2] & 0xff,
orig[3] & 0xff, orig[4] & 0xff, orig[5] & 0xff);& 0xff是为了确保只向printf()发送you 8位;对于像uint8_t这样的无符号类型,它们不应该是必需的,所以您也可以不使用它们。
这假设是一个常规的48位MAC,并使用conventional冒号分隔的十六进制样式进行打印。
发布于 2013-01-16 20:56:53
使用C99格式说明符:
#include <inttypes.h>
printf("%" PRIu8 "\n", orig[0]);https://stackoverflow.com/questions/14358967
复制相似问题