This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: A little bit of C fun...
- From: John Carter <john dot carter at tait dot co dot nz>
- To: "Austin, Alex" <Alex dot Austin at spectrumdsi dot com>
- Cc: me22 <me22 dot ca at gmail dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 23 Oct 2008 11:03:34 +1300 (NZDT)
- Subject: RE: A little bit of C fun...
- References: <alpine.DEB.1.00.0810221735040.30487@parore.tait.co.nz><"fa28b92 5 0810212203u51a1da18n13ae93aabde567a0"@mail.gmail.com><alpine.DEB.1.00.08102 30830390.23033@parore.tait.co.nz><"3DC6D022E7CC5D41A9C A465499463C9E718C1BFEF8"@mtk-sms-exch01.digi.com><3DC6D022E7CC5D41A9CA46549 9463C9E718C1BFEFB@mtk-sms-exch01.digi.com>
On Wed, 22 Oct 2008, Austin, Alex wrote:
Oh, no... I'm dumb.
typedef struct {
int x;
} b;
int a(b *param)
{
return printf("%d\n", b->x);
}
int print_number(int c)
{
return a(&(b){c});
}
Great! You've got it!
Now for extra credit...
Where would this trick be sort of useful?
I shorten it by one character....
a(&(b){})
... (but then it does something subtly more that the previous
one...oooh I'm evil!)
What would your program print if you took out the c and why?
int print_number(void)
{
return a(&(b){});
}
John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand