Create a variable as a reference for a long object in Go

huangapple go评论77阅读模式
英文:

Create a variable as a reference for a long object in Go

问题

我有一个很长的对象update.PostType.RecievedFrom.Id,我需要在程序中多次访问它,但我想要缩短它,使其更易读,通过创建一个变量id := update.PostType.RecievedFrom.Id。现在我的问题是,这个变量是否是一个"零开销"的变量,并且会在编译时被替换为宏,还是它会影响我的程序(如果是的话,我该如何避免)?

英文:

I have a long object update.PostType.RecievedFrom.Id that I need to access many times inside my program,

but I want to shorten it, so it will be more readable, by creating a variable for it id := update.PostType.RecievedFrom.Id. now my question is would this variable be a "zero overhead" variable and will be just replaced as a macro in compile time, or it does affect my program (and if it is, how can I avoid it?)

答案1

得分: 5

> 在编译时,will be just replaced as a macro会被替换为宏吗?

不会。

> 或者它会影响我的程序吗?

会有影响,但是非常微不足道。

> (如果有影响),我该如何避免它?

你无法避免,也不需要担心。

英文:

> will be just replaced as a macro in compile time [?]

No.

> or it does affect my program

Yes, but in a totally negligible way

> (and if it is, how can I avoid it?)

You cannot and you should not bother.

huangapple
  • 本文由 发表于 2022年11月12日 20:01:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/74412753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定