简体   繁体   English

c中的typedef和类型等效

[英]typedef in c and type equivalence

If I do this: 如果我这样做:

typedef int x[10];
x a;

Is it same as: int a[10]; 是否与: int a[10]; ?

是。

Yes its same. 是的,也是一样。 If you want to learn more, go here. 如果您想了解更多,请去这里。

Yes if we speak about syntax. 是的,如果我们谈论语法。 But think about this: 但是考虑一下:

typedef int MyType[5];

/* Some code, large enough fragment */

int func (MyType var)
{
  /* Something that changes */
  return 0;
}

If you see only func() declaration you can think it receives var by value so any change inside function is local. 如果仅看到func()声明,则可以认为它按值接收var,因此函数内部的任何更改都是本地的。 But as actually MyType is array which is pointer changing var inside func() you can change actual caller's variable. 但是实际上MyType是数组,它是在func()中更改var的指针,因此您可以更改实际调用者的变量。

So speaking about concept this is not the same. 因此,谈论概念并不相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM