问题描述
亲爱的伙伴们,
这是对上述C结构的常见(且不常见)非常重要的b $ b使用的另一项调查。
它是由同样的普通C程序员发布的,他们对'enum'的用法做了类似的
调查。
我知道空间优化是''union'背后的关键理念,在
大多数情况下,需要一个类型字段来验证实体的类型
''union''变量中的
。
我只是好奇我的老同事如何利用
C的这个特性他们的实现基于不同的编程风格
多样化的应用领域。
感谢您的关注。
此致,
// rk
另一票:同样
-
| _ CJSonnack <章*** @ Sonnack.com> _____________ |我的节目怎么样? |
| _ ___________________ |致电:1-800-DEV-NULL |
Dear mates,
This is an another survey for the common (and uncommon) nontrivial
uses of the aforementioned C construct.
It''s posted by the same average C programmer who''s made a similar
survey about the uses of ''enum''s.
I know that space optimization is the key idea behind ''union''s, and in
most cases a type-field is necessary to verify the type of the entity
in the ''union'' variable.
I''m just curious about how my elder colleagues utilize this feature of
C in their implementations based on diverse programming styles in
diverse application domains.
Thank you for your interest.
Best regards,
//rk
One place unions are used is in the X Window system. The idea is that the
client and the X server can reside on different machines, and packets can go
over a network. An obvious optimisation is to make each packet of fixed
size, with a type field telling you how to interpret the data - a mouse
click, a request to redraw, etc. The messages are therefore implemented as
unions.
Another vote for: Likewise
--
|_ CJSonnack <Ch***@Sonnack.com> _____________| How''s my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|
In my largest project, 10 years old and going strong, I found exactly
*two* uses of ''union'' in ~500K lines of C code.
And were I refactoring either area of the code base today, I would get
rid of them.
- Sev
这篇关于C程序员!你如何使用'工会'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!