nested functions

nested functions

Post by ah.. » Thu, 10 Jul 2003 04:52:09



Hi,

Sorry to bother you here in the DJGPP mailing list. This might be slightly
off-topic,
but I know there are a couple of bright guys out there who might just know
this... ;-)

I try to figure out _why_ the following code compiles with DJGPP:

int abc(void)
{
  int x = 0;
  int y = 2;

  int def(int r)
  {
    int x = 1;
    return r + x;
  }

  return def(x) + def(y);

Quote:}

int main(void)
{
  return abc();

Quote:}

Could somebody enlighten me whether nested functions are a GCC or DJGPP
extension or whether they are actually part of the C standard.
A reference to the relevant chapter in the standard would be most
appreciated.
I've been digging through the standard(s), but I'm still not sure whether or
not the
above should work.

Thanks for your help,

Tony

--
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++

Jetzt ein- oder umsteigen und USB-Speicheruhr als Pr?mie sichern!

 
 
 

nested functions

Post by DJ Delori » Thu, 10 Jul 2003 05:25:20


Quote:> Could somebody enlighten me whether nested functions are a GCC or DJGPP
> extension or whether they are actually part of the C standard.

Nested functions are a GCC extension.

 
 
 

nested functions

Post by Hans-Bernhard Broeke » Thu, 10 Jul 2003 14:56:53



> Could somebody enlighten me whether nested functions are a GCC or DJGPP
> extension or whether they are actually part of the C standard.

A GCC extension, as clearly documented here:

        info gcc "C Extensions" "Nested Functions"

Another way you can tell is that it will fail to compile if you put
GCC into ANSI-C-only mode (gcc -ansi -pedantic for GCC 2, something
else for GCC 3.x).

--

Even if all the snow were burnt, ashes would remain.

 
 
 

nested functions

Post by ah.. » Thu, 10 Jul 2003 20:43:51


Quote:> > Could somebody enlighten me whether nested functions are a GCC or DJGPP
> > extension or whether they are actually part of the C standard.

> Nested functions are a GCC extension.

Thanks DJ and H-B for your quick response.
I did try the -ansi but obviously forgot the -pedantic.

Regards,

Tony

--
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++

Jetzt ein- oder umsteigen und USB-Speicheruhr als Pr?mie sichern!

 
 
 

nested functions

Post by To » Fri, 11 Jul 2003 01:00:26




> > Could somebody enlighten me whether nested functions are a GCC or DJGPP
> > extension or whether they are actually part of the C standard.

> A GCC extension, as clearly documented here:

>    info gcc "C Extensions" "Nested Functions"

> Another way you can tell is that it will fail to compile if you put
> GCC into ANSI-C-only mode (gcc -ansi -pedantic for GCC 2, something
> else for GCC 3.x).

In GCC 3.x, -pedantic is what is required, but even it will only
generate a warning.  (If you really want to prevent compilation
entirely, you need -pedantic-errors).  Oddly, -ansi does not diable
the nested function extension, because it only disables extensions
that are "incompatible" with ISO C90.

For most beginners, and for me as well, turning on all, or almost all,
warnings is usually best.  This pretty much does it:

-Wall -W -pedantic

For reasons I don't understand, -W turns on warnings that -Wall does
not.  I believe there is a proposal (perhaps it was already adopted)
to change the name of -W to something that more clearly expresses what
that compiler option does.

Best regards,

Tom

 
 
 

1. Nested inlined functions question

Call me lazy if you want, but it seems to me that it's a bit hard to test the
following. If I have functions declared something like what follows:

extern inline void do_something(void)
  {
  ...
  }

extern inline void do_something_more(void)
  {
  ...
  do_something();
  ...
  }

Assuming do_something() does nothing to prevent it from being inlined, and
that do_something_more doesn't do anything to prevent it from being inlined
either, will a call to do_something_more inline both functions? This is
important to me, because I have several interrelated math functions. It would
be much easier for maintenance if I could just implement them once and then
call them and they'd still be inlined. If they're not automatically inlined, I
have to rewrite them in each math subfunction where I need them.

Sincerely yours,

Sebastien Loisel

2. >> Windows 98SE Boot-up Hang <<

3. shell nesting level

4. CMD contact.

5. Plug-in Windows enhancement, nested groups

6. VB Script

7. Problem: nested FOR loops in .BTM

8. Serial/USB IR Port

9. Problem with nested #include's

10. Solving the Win2K nested DPMI bug: Cygwin?

11. Nested structure problem (maybe)?

12. Is Nested DPMI Possible?

13. BREAKing out of a nested loop