Re: [vox] unions [was: ACM article: 'Study: IT Budgets Opening Up to Lin
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox] unions [was: ACM article: 'Study: IT Budgets Opening Up to Linux']
On Fri, Aug 24, 2001 at 02:48:38PM -0700, Jeff Newmiller wrote:
> On Fri, 24 Aug 2001, Gabriel Rosa wrote:
>
> > On Fri, 24 Aug 2001, Peter Jay Salzman wrote:
> >
> > > btw, in all my years of coding C, i just used a union for the first time.
> > > i feel like celebrating. :) also wrote my first lex program. now the
> > > big trick will be writing the bison companion. oi vey.
> > >
> >
> > I can think of many uses for them, but none in projects that I want to
> > undertake. Conceptually, they are very cool, but as one of my cs profs said
> > (loosely), "In 15 years of C, I've seen 1 person use a union for a good
> > reason".
>
> In 15 years, I have used them a couple of times "for a good reason".
> Most interesting one was in a menu datastructure in an embedded C program.
> Kept data requirements small and allowed "polymorphic" data handling. In
> other cases, I setup various implementation-specific data format
> converters with them.
>
> But yes, good uses are rare.
>
> > Congrats! ;)
>
> Seconded ... and we won't even ask if your reasons were pure. :)
He used a union for the type of semantic values in his bison code -
the only way to have values of different types for different tokens in
bison.
Micah
|