Bir başlık dosyasında önceden tanımlanmış bir .c dosyasındaki bir işlevin yeniden tanımlanmasına izin vermek istiyorum. Yapmak istediğim tam olarak ne gibi seslerBu zayıf kullanım mı?
The effect is equivalent to moving all references to the alias to a separate translation unit, renaming the alias to the aliased symbol, declaring it as weak, compiling the two separate translation units and performing a reloadable link on them.
: weakref özellik hakkında GCC kılavuzuna göre. Ancak, aşağıdaki örnekte hata ile derleme değil: bunu doğru kullanıyor muyum
tpp.c:18:13: error: redefinition of ‘foo’ tpp.c:6:13: note: previous definition of ‘foo’ was here
#include <sys/types.h>
#include <stdio.h>
/* this will be in a header file */
static void foo(void) __attribute__ ((weakref ("_foo")));
static void _foo(void)
{
printf("default foo\n");
}
/* in a .c file #including the header mentioned above */
#define CUSTOM_FOO
#ifdef CUSTOM_FOO
static void foo(void)
{
printf("user defined foo.\n");
}
#endif
int main(int argc, char **argv)
{
printf("calling foo.\n");
foo();
}
? Neyi kaçırıyorum?
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
'zayıf' ve 'zayıf' iki farklı şeydir (https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Function-Attributes.html#Function-Attributes). Soru 'zayıf' ile ilgili ve 'zayıf' kullanarak cevapladınız. – Nawaz