Subject: Functions returning strings (was: magic symlinks: uid keyword translation)
To: None <>
From: Christian Biere <>
List: tech-kern
Date: 10/31/2006 15:15:21
Alan Barrett wrote:
> On Mon, 30 Oct 2006, Christian Biere wrote:
> > Of course, the additionally required variable is somewhat awkward
> > but you can't even write this, unfortunately:
> > 
> > 	printf("%s", uid_to_string_buf(uid).str); /* not legal */
> What's wrong with that?  If a function returns a struct or union, you
> are allowed to use just one member.  Try it, or read section of
> the C99 standard.

I have tried it and GCC wouldn't allow it. Now, if I use -std=c99 it does
indeed "work". Without this option, you get a strange warning and the compiled
executable crashes and I see no way to cast this to satisfy the compiler. There
are only very few in new features C99 that I consider useful so I usually try
to avoid it. In this case, I myself just wouldn't mind the additional variable,
after all you need one when using "snprintf(buf, sizeof buf, ...) " anyway, so
that's not the disadvantage.