RE: A little bit of C fun...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx
New Zealand


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux