[英]Conflicting function declaration and macro?
我在linux内核中查看这个头文件: https : //elixir.bootlin.com/linux/v4.14/source/arch/x86/boot/string.h
#ifndef BOOT_STRING_H
#define BOOT_STRING_H
/* Undef any of these macros coming from string_32.h. */
#undef memcpy
#undef memset
#undef memcmp
void *memcpy(void *dst, const void *src, size_t len);
void *memset(void *dst, int c, size_t len);
int memcmp(const void *s1, const void *s2, size_t len);
#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
#define memset(d,c,l) __builtin_memset(d,c,l)
#define memcmp __builtin_memcmp
...
#endif /* BOOT_STRING_H */
我无法弄清楚#undef +函数声明+宏在memcpy,memset和memcmp上的定义是什么。 例如,它首先声明一个函数memcpy,然后在此之后定义一个宏memcpy。 我不确定这是什么目的。 我发现这个函数在这里定义: https : //elixir.bootlin.com/linux/v4.14/source/arch/x86/boot/copy.S#L20 。 如果代码中的某个地方使用memcpy(例如这里: https : //elixir.bootlin.com/linux/v4.14/source/arch/x86/boot/main.c#L40 )使用memcpy它使用什么? copy.S或__builtin_memcpy中定义的函数?
函数声明和宏没有冲突。 memcpy()
具有在内核,其在通过上述的注释暗示几种定义#undef
块-有另一个memcpy()
中所定义string_32.h 。
#undef memcpy
正在取消string_32.h中找到的#define
,这样它就不会存在于包含/boot/string.h的任何文件中。 然后声明memcpy()
,并为它构建一个新的宏。
#define
语句正在为memcpy()
创建一个新的宏,因为string_32.h中的一个不再存在于此上下文中。 内核开发人员出于各种原因使用宏; 请参阅此主题中的答案以获取更多信
/boot/copy.S是一个程序集文件 。 你可以在这里阅读一下它的作用。 /boot/main.c中使用的memcpy()
来自/boot/string.h - 检查include语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.