public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* We are nesting functions now?
@ 2002-12-11 20:06 Matt Young
  2002-12-11 21:33 ` kwall
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Young @ 2002-12-11 20:06 UTC (permalink / raw)
  To: gcc

/* This seems to work */
int  main() {
        void fi() {
                void f2() {
                        printf("F2\n");
                        }
                void f3() {
                        printf("F3\n");
                        f2();
                        }
                printf("F1\n");
                }
        fi();
        f3();
        return 1;
}

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

* Re: We are nesting functions now?
  2002-12-11 20:06 We are nesting functions now? Matt Young
@ 2002-12-11 21:33 ` kwall
  2002-12-11 22:19   ` Timothy J. Wood
  0 siblings, 1 reply; 5+ messages in thread
From: kwall @ 2002-12-11 21:33 UTC (permalink / raw)
  To: GCC List

Feigning erudition, Matt Young wrote:
% /* This seems to work */
% int  main() {
%         void fi() {
%                 void f2() {
%                         printf("F2\n");
%                         }
%                 void f3() {
%                         printf("F3\n");
%                         f2();
%                         }
%                 printf("F1\n");
%                 }
%         fi();
%         f3();
%         return 1;
% }

Please define "seems to work". After #including stdio.h,

[~/src]$ cc -Wall nest.c
nest.c: In function `main':
nest.c:15: warning: implicit declaration of function `f3'
/tmp/cc4UlMpa.o: In function `main':
/tmp/cc4UlMpa.o(.text+0x82): undefined reference to `f3'
collect2: ld returned 1 exit status
[~/src]$ gcc -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
Configured with: ../gcc-3.2/configure --enable-threads --enable-shared --enable-static --disable-nls --enable-languages=c,c++,g77,objective-c
Thread model: posix
gcc version 3.2

Kurt
-- 
Steinbach's Guideline for Systems Programming:
	Never test for an error condition you don't know how to
handle.

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

* Re: We are nesting functions now?
  2002-12-11 21:33 ` kwall
@ 2002-12-11 22:19   ` Timothy J. Wood
  2002-12-12  6:49     ` Kris Warkentin
  0 siblings, 1 reply; 5+ messages in thread
From: Timothy J. Wood @ 2002-12-11 22:19 UTC (permalink / raw)
  To: kwall; +Cc: GCC List



   If you move the call to f3 so that it is in the proper scope, this 
works:

% cc -Wall foo.c -o foo
% ./foo
F1
F3
F2
% cc -v
cc -v
Reading specs from /usr/libexec/gcc/darwin/ppc/3.1/specs
Thread model: posix
Apple Computer, Inc. GCC version 1173, based on gcc version 3.1 
20020420 (prerelease)


#include <stdio.h>
int  main() {
     void fi() {
         void f2() {
             printf("F2\n");
         }
         void f3() {
             printf("F3\n");
             f2();
         }
         printf("F1\n");
         f3();
     }
     fi();
     return 1;
}

-tim

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

* Re: We are nesting functions now?
  2002-12-11 22:19   ` Timothy J. Wood
@ 2002-12-12  6:49     ` Kris Warkentin
  2002-12-12 17:47       ` Paul Brook
  0 siblings, 1 reply; 5+ messages in thread
From: Kris Warkentin @ 2002-12-12  6:49 UTC (permalink / raw)
  To: kwall, Timothy J. Wood; +Cc: GCC List

It's a gcc extension.  Probably in there for Pascal support.

http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Nested-Functions.html#Nested%20Fun
ctions

cheers,

Kris
----- Original Message -----
From: "Timothy J. Wood" <tjw@omnigroup.com>
To: <kwall@kurtwerks.com>
Cc: "GCC List" <gcc@gnu.org>
Sent: Thursday, December 12, 2002 1:00 AM
Subject: Re: We are nesting functions now?


>
>
>    If you move the call to f3 so that it is in the proper scope, this
> works:
>
> % cc -Wall foo.c -o foo
> % ./foo
> F1
> F3
> F2
> % cc -v
> cc -v
> Reading specs from /usr/libexec/gcc/darwin/ppc/3.1/specs
> Thread model: posix
> Apple Computer, Inc. GCC version 1173, based on gcc version 3.1
> 20020420 (prerelease)
>
>
> #include <stdio.h>
> int  main() {
>      void fi() {
>          void f2() {
>              printf("F2\n");
>          }
>          void f3() {
>              printf("F3\n");
>              f2();
>          }
>          printf("F1\n");
>          f3();
>      }
>      fi();
>      return 1;
> }
>
> -tim
>
>

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

* Re: We are nesting functions now?
  2002-12-12  6:49     ` Kris Warkentin
@ 2002-12-12 17:47       ` Paul Brook
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Brook @ 2002-12-12 17:47 UTC (permalink / raw)
  To: Kris Warkentin, kwall, Timothy J. Wood; +Cc: GCC List

On Thursday 12 December 2002 1:57 pm, Kris Warkentin wrote:
> It's a gcc extension.  Probably in there for Pascal support.

Also used by the fortran frontends.

>
> http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Nested-Functions.html#Nested%20
>Functions

Paul Brook

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

end of thread, other threads:[~2002-12-13  1:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-11 20:06 We are nesting functions now? Matt Young
2002-12-11 21:33 ` kwall
2002-12-11 22:19   ` Timothy J. Wood
2002-12-12  6:49     ` Kris Warkentin
2002-12-12 17:47       ` Paul Brook

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).