public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* A little bit of C fun...
@ 2008-10-22  4:45 John Carter
       [not found] ` <fa28b925 0810212203u51a1da18n13ae93aabde567a0@mail.gmail.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: John Carter @ 2008-10-22  4:45 UTC (permalink / raw)
  To: gcc-help

I'm having a little fun going around hurting peoples brains...

Consider for a moment this program excerpt...
   a(&(b){c})

Is this valid C++?

Is this valid C?

What would you need to do to get this to compile?

What does it do?

Could it be tweaked into something useful? (apart from using it to
hurt people's brains with.)



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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A little bit of C fun...
  2008-10-22  4:45 A little bit of C fun John Carter
       [not found] ` <fa28b925 0810212203u51a1da18n13ae93aabde567a0@mail.gmail.com>
@ 2008-10-22  5:04 ` me22
  2008-10-22 19:38   ` John Carter
       [not found] ` <"fa28b92 5  0810212203u51a1da18n13ae93aabde567a0"@mail.gmail.com>
  2 siblings, 1 reply; 13+ messages in thread
From: me22 @ 2008-10-22  5:04 UTC (permalink / raw)
  To: John Carter; +Cc: gcc-help

On Wed, Oct 22, 2008 at 00:44, John Carter <john.carter@tait.co.nz> wrote:
>
> Consider for a moment this program excerpt...
>  a(&(b){c})
>
> Is this valid C++?
>
> Is this valid C?
>
> What would you need to do to get this to compile?
>

Use the preprocessor.  Otherwise you can't get braces inside parens.

#define c return 0;
#define b d)
#define a(T) int d; if (T

int main() {
    a(&(b){c})
}

> What does it do?
>

Whatever you want.

> Could it be tweaked into something useful? (apart from using it to
> hurt people's brains with.)
>

No.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A little bit of C fun...
  2008-10-22  5:04 ` me22
@ 2008-10-22 19:38   ` John Carter
  2008-10-22 20:13     ` Austin, Alex
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: John Carter @ 2008-10-22 19:38 UTC (permalink / raw)
  To: me22; +Cc: gcc-help

On Wed, 22 Oct 2008, me22 wrote:

> Use the preprocessor.  Otherwise you can't get braces inside parens.

Nope. I didn't use preprocessor. But warped kudos to you for thinking
of it.

Since you are all struggling, I'll make it easier for you.

I shorten it by one character....
    a(&(b){})

... (but then it does something subtly more that the previous
one...oooh I'm evil!)


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: A little bit of C fun...
  2008-10-22 19:38   ` John Carter
@ 2008-10-22 20:13     ` Austin, Alex
  2008-10-22 20:16       ` Austin, Alex
  2008-10-22 22:03     ` me22
  2008-11-29 20:52     ` code snippet sagrav
  2 siblings, 1 reply; 13+ messages in thread
From: Austin, Alex @ 2008-10-22 20:13 UTC (permalink / raw)
  To: John Carter, me22; +Cc: gcc-help

A guess:
b is a type, and a is a function that takes a pointer to a function that returns b?

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of John Carter
Sent: Wednesday, October 22, 2008 2:38 PM
To: me22
Cc: gcc-help@gcc.gnu.org
Subject: Re: A little bit of C fun...

On Wed, 22 Oct 2008, me22 wrote:

> Use the preprocessor.  Otherwise you can't get braces inside parens.

Nope. I didn't use preprocessor. But warped kudos to you for thinking
of it.

Since you are all struggling, I'll make it easier for you.

I shorten it by one character....
    a(&(b){})

... (but then it does something subtly more that the previous
one...oooh I'm evil!)


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: A little bit of C fun...
  2008-10-22 20:13     ` Austin, Alex
@ 2008-10-22 20:16       ` Austin, Alex
  0 siblings, 0 replies; 13+ messages in thread
From: Austin, Alex @ 2008-10-22 20:16 UTC (permalink / raw)
  To: Austin, Alex, John Carter, me22; +Cc: gcc-help

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});
}

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of Austin, Alex
Sent: Wednesday, October 22, 2008 3:13 PM
To: John Carter; me22
Cc: gcc-help@gcc.gnu.org
Subject: RE: A little bit of C fun...

A guess:
b is a type, and a is a function that takes a pointer to a function that returns b?

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of John Carter
Sent: Wednesday, October 22, 2008 2:38 PM
To: me22
Cc: gcc-help@gcc.gnu.org
Subject: Re: A little bit of C fun...

On Wed, 22 Oct 2008, me22 wrote:

> Use the preprocessor.  Otherwise you can't get braces inside parens.

Nope. I didn't use preprocessor. But warped kudos to you for thinking
of it.

Since you are all struggling, I'll make it easier for you.

I shorten it by one character....
    a(&(b){})

... (but then it does something subtly more that the previous
one...oooh I'm evil!)


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: A little bit of C fun...
       [not found]       ` <3DC6D022E7CC5D41A9CA465499463C9E718C1BFEF8@mtk-sms-exch01.digi .com>
@ 2008-10-22 22:00         ` John Carter
  0 siblings, 0 replies; 13+ messages in thread
From: John Carter @ 2008-10-22 22:00 UTC (permalink / raw)
  To: Austin, Alex; +Cc: me22, gcc-help

On Wed, 22 Oct 2008, Austin, Alex wrote:

> b is a type, and a is a function that takes a pointer to a function
> that returns b?

b is a type.
a is a function that takes a pointer to...

So far so good. Nearly, but not quite, keep trying.


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A little bit of C fun...
  2008-10-22 19:38   ` John Carter
  2008-10-22 20:13     ` Austin, Alex
@ 2008-10-22 22:03     ` me22
  2008-10-22 22:35       ` John Carter
  2008-11-29 20:52     ` code snippet sagrav
  2 siblings, 1 reply; 13+ messages in thread
From: me22 @ 2008-10-22 22:03 UTC (permalink / raw)
  To: John Carter; +Cc: gcc-help

On Wed, Oct 22, 2008 at 15:37, John Carter <john.carter@tait.co.nz> wrote:
> On Wed, 22 Oct 2008, me22 wrote:
>
>> Use the preprocessor.  Otherwise you can't get braces inside parens.
>
> Nope. I didn't use preprocessor. But warped kudos to you for thinking
> of it.
>

Say, what about -std=gnu++0x?  Then the braces can be an initializer list...

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: A little bit of C fun...
       [not found]         ` <3DC6D022E7CC5D41A9CA465499463C9E718C1BFEFB@mtk-sms-exch01.digi .com>
@ 2008-10-22 22:04           ` John Carter
  0 siblings, 0 replies; 13+ messages in thread
From: John Carter @ 2008-10-22 22:04 UTC (permalink / raw)
  To: Austin, Alex; +Cc: me22, gcc-help

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A little bit of C fun...
  2008-10-22 22:03     ` me22
@ 2008-10-22 22:35       ` John Carter
  2008-10-22 23:12         ` John Carter
  0 siblings, 1 reply; 13+ messages in thread
From: John Carter @ 2008-10-22 22:35 UTC (permalink / raw)
  To: me22; +Cc: gcc-help

On Wed, 22 Oct 2008, me22 wrote:

> On Wed, Oct 22, 2008 at 15:37, John Carter <john.carter@tait.co.nz> wrote:
>> On Wed, 22 Oct 2008, me22 wrote:
>>
>>> Use the preprocessor.  Otherwise you can't get braces inside parens.
>>
>> Nope. I didn't use preprocessor. But warped kudos to you for thinking
>> of it.
>>
>
> Say, what about -std=gnu++0x?  Then the braces can be an initializer list...
>

I compiled this with gcc 3 and gcc 4 using -std=c89 and -std=c99 with
-Wall and -W.

gcc-2.95 failed
   a(&(b){c}) 
but passed
   a((b){c})


-W warns about a(&(b){}) but that is one of those cases where -W
  warns about a potential omission in a legal operation.

And yes, you're on the right track now, the braces are an initializer list.



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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: A little bit of C fun...
  2008-10-22 22:35       ` John Carter
@ 2008-10-22 23:12         ` John Carter
  0 siblings, 0 replies; 13+ messages in thread
From: John Carter @ 2008-10-22 23:12 UTC (permalink / raw)
  To: gcc-help

On Thu, 23 Oct 2008, John Carter wrote:

> I compiled this with gcc 3 and gcc 4 using -std=c89 and -std=c99 with
> -Wall and -W.
> -W warns about a(&(b){}) but that is one of those cases where -W
> warns about a potential omission in a legal operation.

Ah. I forgot to say -pedantic with the -std=

If I say -pedantic gcc only accepts this stuff for -std=c99 and
doesn't accept the {} empty initializer. (Not that it matters, in that
something still interesting occurs with the {c} version if it contains
more than one field.)



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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* code snippet
  2008-10-22 19:38   ` John Carter
  2008-10-22 20:13     ` Austin, Alex
  2008-10-22 22:03     ` me22
@ 2008-11-29 20:52     ` sagrav
  2008-11-29 23:53       ` Sven Eschenberg
  2 siblings, 1 reply; 13+ messages in thread
From: sagrav @ 2008-11-29 20:52 UTC (permalink / raw)
  To: gcc-help

I need a C code snippet to display a *.html file in the web browser. 

Help will be appreciated,

thanks in advance.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: code snippet
  2008-11-29 20:52     ` code snippet sagrav
@ 2008-11-29 23:53       ` Sven Eschenberg
  0 siblings, 0 replies; 13+ messages in thread
From: Sven Eschenberg @ 2008-11-29 23:53 UTC (permalink / raw)
  To: gcc-help

Wrong list!

This is a gcc specific help list - you might want to try something like 
a general purpose C help list.

-Sven


sagrav schrieb:
> I need a C code snippet to display a *.html file in the web browser.
> Help will be appreciated,
>
> thanks in advance.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: code snippet
       [not found] <20081129220208.GA5894@gmx.de>
@ 2008-11-30 18:02 ` sagrav
  0 siblings, 0 replies; 13+ messages in thread
From: sagrav @ 2008-11-30 18:02 UTC (permalink / raw)
  To: gcc-help, Marc Weber

Thans for your help, Mark:


> Hi sagrav,
>
> there are many ways to accomplish this and I really don't know which one
> you have in mind?
What I want to do is just to open a "help.html" file with the default 
browser of the host where the program is running.

> The simplest way is just running a browser eg using
> execve("opera", [ ... args ] )
I think this option limits to a specific browser.

> Just google on how to launch another program using C.
> The other way is using a framework such as gtk and use a component such
...

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-11-30 16:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-22  4:45 A little bit of C fun John Carter
     [not found] ` <fa28b925 0810212203u51a1da18n13ae93aabde567a0@mail.gmail.com>
     [not found]   ` <alpine.DEB.1.00.081023 0830390.23033@parore.tait.co.nz>
2008-10-22  5:04 ` me22
2008-10-22 19:38   ` John Carter
2008-10-22 20:13     ` Austin, Alex
2008-10-22 20:16       ` Austin, Alex
2008-10-22 22:03     ` me22
2008-10-22 22:35       ` John Carter
2008-10-22 23:12         ` John Carter
2008-11-29 20:52     ` code snippet sagrav
2008-11-29 23:53       ` Sven Eschenberg
     [not found] ` <"fa28b92 5  0810212203u51a1da18n13ae93aabde567a0"@mail.gmail.com>
     [not found]   ` <"alpine.DEB.1.00.0810  23  0830390.23033"@parore.tait.co.nz>
     [not found]   ` <"alpine.DEB.1.00.0810 2  30830390.23033"@parore.tait.co.nz>
     [not found]     ` <3DC6D022E7CC5D41A9CA465499463C9E718C1BFE F8@mtk-sms-exch01.digi.com>
     [not found]       ` <3DC6D022E7CC5D41A9CA465499463C9E718C1BFEF8@mtk-sms-exch01.digi .com>
2008-10-22 22:00         ` A little bit of C fun John Carter
     [not found]   ` <alpine.DEB.1.00.08102 30830390.23033@parore.tait.co.nz>
     [not found]     ` <"3DC6D022E7CC5D41A9C  A465499463C9E718C1BFEF8"@mtk-sms-exch01.digi.com>
     [not found]       ` <3DC6D022E7CC5D41A9CA46549 9463C9E718C1BFEFB@mtk-sms-exch01.digi.com>
     [not found]         ` <3DC6D022E7CC5D41A9CA465499463C9E718C1BFEFB@mtk-sms-exch01.digi .com>
2008-10-22 22:04           ` John Carter
     [not found] <20081129220208.GA5894@gmx.de>
2008-11-30 18:02 ` code snippet sagrav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).