1

Is there a structural type equivalence in C?

4

3 に答える 3

3

Strictly, no - differently named types are different types, even if the structure of the types is the same. (Of course, a typedef just introduces an alternative name for an existing type; such types are the same type.)

However, in practice, there are a number of stunts you can pull and get away with. But strictly, they are cheating. Using void pointers is one way of subverting the system; another is not using prototype declarations of functions; variable length argument lists can be another.

于 2011-01-29T07:29:25.700 に答える
0

2つを比較して同等かどうかを尋ねている場合struct、答えはノーです。代入のみがあり、関数から構造体を返すことができます。

于 2011-01-29T07:38:32.013 に答える
-2

C には 2 つの構造体を比較する演算子はありません。代わりに memcmp を使用できます。

if( memcmp( &structvar1, &structvar2, sizeof structvar1 ) )
  puts("not equal");
else
  puts("equal");
于 2011-01-29T08:16:16.063 に答える