This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: A little bit of C fun...


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]