Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #41359

Re: complex declarations

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: complex declarations
Date 2014-03-04 17:05 -0500
Organization Self
Message-ID <53164E3B.3090800@verizon.net> (permalink)
References <lf5cdv$dll$1@dont-email.me> <53163C3C.8060203@verizon.net> <lf5hca$oqi$1@dont-email.me>

Show all headers | View raw


On 03/04/2014 04:42 PM, Robbie Brown wrote:
> On 04/03/14 20:49, James Kuyper wrote:
>> On 03/04/2014 03:18 PM, Robbie Brown wrote:
>>> I have the following code
> 
> <snip>
> 
>> C function definitions can only occur at file scope (6.9p1). You can
>> declare a function at block scope (6.8p2), but you can't define it
>> there. Because you can't define it with block scope, I also personally
>> feel it's a bad idea to declare it at file scope - but that's just a
>> personal preference, not a C rule.
>>
>> If you got this code to compile (except for the part you're asking
>> about), then you're taking advantage of a non-conforming extension to C
>> which allows block scope definitions of functions.
> 
> I used gcc -std=c99 complexdecl.c and you are right. Apparently the 
> ability to define a function within a function (nesting of functions) is 
> a gcc extension, sheesh, you really gotta be on the ball with this stuff 
> haven't you?

If you add "-pedantic" to "-std=c99", you will have eliminated most of
your dependence on gcc extensions, though I personally would recommend
adding "-Wall -Wpointer-arith -Wcast-align -Wstrict-prototypes
-Wmissing-prototypes" as well. Other people like to turn on several
additional warnings, particularly -Wextra, but I find a lot of those
warnings to be spurious.

> <snip>
> 
>> That's because you start out declaring an identifier named x to be a
>> pointer to a function taking an argument of type int. Then you try to
>> follow that up with the declaration of signal3. You can declare the name
>> of a function and the names of it's arguments, but you can't declare a
>> name for the value returned by that function.

<snip incorrect advice from my previous message, except for final
recommendation:>
...
>> 	void (*)(int) signal3(int x, void(*y)(int))
> 
> That was one of the first things I tried and for some reason that 
> (obviously) escapes me it doesn't compile.

That's because I managed to get confused during the process of
responding to you. I put a lot of effort into making that message
complete; I should have put a bit more effort into making it correct. A
simple test compile would have reminded me of my error, and I would have
known how to correct it, but I didn't do such a test.

Ben's answer is the correct one, and it renders irrelevant everything I
said about type names. It was all correct (I think), except for the part
about a type name being the answer to your problem. :-(

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

complex declarations Robbie Brown <dac@nomail.invalid> - 2014-03-04 20:18 +0000
  Re: complex declarations James Kuyper <jameskuyper@verizon.net> - 2014-03-04 15:49 -0500
    Re: complex declarations James Kuyper <jameskuyper@verizon.net> - 2014-03-04 16:06 -0500
      Re: complex declarations Robbie Brown <dac@nomail.invalid> - 2014-03-05 12:18 +0000
        Re: complex declarations "BartC" <bc@freeuk.com> - 2014-03-05 12:56 +0000
          Re: complex declarations James Kuyper <jameskuyper@verizon.net> - 2014-03-05 08:24 -0500
            Re: complex declarations "BartC" <bc@freeuk.com> - 2014-03-05 16:26 +0000
        Re: complex declarations James Kuyper <jameskuyper@verizon.net> - 2014-03-05 08:13 -0500
          Re: complex declarations Robbie Brown <dac@nomail.invalid> - 2014-03-05 13:32 +0000
        Re: complex declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-05 14:32 +0000
    Re: complex declarations Robbie Brown <dac@nomail.invalid> - 2014-03-04 21:42 +0000
      Re: complex declarations Keith Thompson <kst-u@mib.org> - 2014-03-04 14:04 -0800
        Re: complex declarations Robbie Brown <dac@nomail.invalid> - 2014-03-05 09:22 +0000
          Re: complex declarations James Kuyper <jameskuyper@verizon.net> - 2014-03-05 07:29 -0500
            Re: complex declarations Keith Thompson <kst-u@mib.org> - 2014-03-05 08:38 -0800
      Re: complex declarations James Kuyper <jameskuyper@verizon.net> - 2014-03-04 17:05 -0500
  Re: complex declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-04 21:15 +0000
    Re: complex declarations "BartC" <bc@freeuk.com> - 2014-03-04 21:38 +0000
      Re: complex declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-04 23:27 +0000
    Re: complex declarations Robbie Brown <dac@nomail.invalid> - 2014-03-04 21:59 +0000
      Re: complex declarations James Kuyper <jameskuyper@verizon.net> - 2014-03-04 17:12 -0500
      Re: complex declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-05 00:28 +0000
        Re: complex declarations Robbie Brown <dac@nomail.invalid> - 2014-03-05 09:10 +0000
          Re: complex declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-05 11:44 +0000

csiph-web