0

I have known nested functions are supported as an extension in gcc, but I compile a c file used nested function with an error. Error massage is like this:

test.cpp:6:40: error: function definition is not allowed here double

square (double z) { return z * z; }

And nested function is like this:

foo (double a, double b)
 {
  double square (double z) { return z * z; }
  return square (a) + square (b);
 }

My operation system is Mac Os, and version is 10.12.6

When I enter gcc -v in iTerm2, the response is this:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Community
  • 1
  • 1
tinyfeng
  • 21
  • 4

1 Answers1

0

You're actually using using Clang, not gcc.

Notice this

Apple LLVM version 9.0.0 (clang-900.0.38)

From the clang website, Clang vs GCC (GNU Compiler Collection)

GCC supports many language extensions, some of which are not implemented by Clang. For instance, in C mode, GCC supports nested functions and has an extension allowing VLAs in structs.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261