Интересный вопрос; обманули это сам; mostly due to horrid hacks involving dubious type casts on innocent memory-blocks.
Этот ответ действительно просто следствие R's ответ, который в значительной степени прибивает вопрос (хотя я не совсем уверен в and goes out of scope after that function ends..
битном)
Для меня ключом к этому является прочтение :
(1) ISO C99 6.7.2:
Два типа имеют совместимый тип, если их типы совпадают. Дополнительные правила для определения совместимости двух типов в 6.7.2 для спецификаторов типов, в 6.7.3 для классификаторов типов, и в 6.7.5 для деклараторов.46) Кроме того, два типа структуры, объединения или перечисления объявленные в отдельных единицах перевода, совместимы , если их теги и элементы удовлетворяют следующим требованиям: Если один объявлен с тегом, другой должен быть объявлен с тем же тегом. ...
(2) C namespaces
Во всяком случае, вот некоторый код (~ несколько единиц перевода), которые, мы надеемся, демонстрирует некоторые, возможно, удивительное поведение для тех, которые еще не ударил этот выпуск раньше:
бла.с:
#include <stdio.h>
struct bar {int a; int b;} stbar;
struct bar_ {int a; int d;} stbar_;
void foo(struct bar* pst);
void foo_(struct bar st);
void callfoo()
{
/*no warnings; possibly surprising results ! */
stbar.a=313;
stbar.b=31313;
foo(&stbar);
printf("called foo() with stbar: %d, %d\n", stbar.a, stbar.b);
/*generates incompatible types warnings:
blah.c:23:5: warning: passing argument 1 of ‘foo’ from incompatible pointer type [enabled by default]
blah.c:6:6: note: expected ‘struct bar *’ but argument is of type ‘struct bar_ *’ */
stbar_.a=313;
stbar_.d=31313;
foo(&stbar_);
printf("called foo() with stbar_: %d, %d\n", stbar_.a, stbar_.d);
/*generates incompatible types warnings:
blah.c:31:5: warning: passing argument 1 of ‘foo’ from incompatible pointer type [enabled by default]
blah.c:6:6: note: expected ‘struct bar *’ but argument is of type ‘struct bar *’ */
struct bar {float s; float t;} stbar;
foo(&stbar);
printf("called foo() with locally defined stbar: %f, %f\n", stbar.s, stbar.t);
}
void callfoo_()
{
stbar.a=313;
stbar.b=31313;
//passing in incompatible type by value ~ no warnings; possibly surprising results !
foo_(stbar);
/*uncomenting next line generates compiler error:
blah.c:47:5: error: incompatible type for argument 1 of ‘foo_’
blah.c:7:6: note: expected ‘struct bar’ but argument is of type ‘struct bar_’ */
//foo_(stbar_);
}
void main()
{
callfoo();
callfoo_();
}
blah_.c:
#include <stdio.h>
struct bar {int x; float z;} stbar;
void foo(struct bar* pst)
{
printf("foo : %d, %f\n", pst->x, pst->z);
pst->x=13;
pst->z=13.13;
}
void foo_(struct bar st)
{
printf("foo_ : %d, %f\n", st.x, st.z);
st.x=13;
st.z=13.13;
}
выход:
$ gcc blah.c blah_.c
blah.c: In function ‘callfoo’:
blah.c:23:5: warning: passing argument 1 of ‘foo’ from incompatible pointer type [enabled by default]
blah.c:6:6: note: expected ‘struct bar *’ but argument is of type ‘struct bar_ *’
blah.c:31:5: warning: passing argument 1 of ‘foo’ from incompatible pointer type [enabled by default]
blah.c:6:6: note: expected ‘struct bar *’ but argument is of type ‘struct bar *’
$ ./a.out
foo : 313, 0.000000
called foo() with stbar: 13, 1095898235
foo : 313, 0.000000
called foo() with stbar_: 13, 1095898235
foo : 13274075, 0.000000
called foo() with locally defined stbar: 0.000000, 13.130000
foo_ : 313, 0.000000
$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 ...
Следствие следствия: славить богов для C++ namespace
с.
Просим выслать код для минимального воспроизведения этой ошибки компиляции –
В дополнение к минимальному, полному примеру, воспроизводящему ошибку, может быть полезно узнать, какая версия GCC это. Является ли это снимком/предварительным выпуском, включенным в некоторый дистрибутив? Стиль предупреждения выглядит довольно недавно. – Flexo
Может быть, определение для 'struct netif' в области видимости в обоих местах для другого? – pmg