编译使用嵌套函数的c文件时出错[重复]

问题描述 投票:-1回答:1

这个问题在这里已有答案:

我知道嵌套函数作为gcc中的扩展支持,但是我使用嵌套函数编译了一个带有错误的c文件。错误按摩是这样的:

test.cpp:6:40:错误:此处不允许函数定义double

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

嵌套函数是这样的:

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

我的操作系统是Mac Os,版本是10.12.6

当我在iTerm2中输入gcc -v时,响应如下:

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
c gcc clang nested-function
1个回答
0
投票

你实际上使用的是Clang,而不是gcc

注意这个

Apple LLVM version 9.0.0 (clang-900.0.38)

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

GCC支持许多语言扩展,其中一些不是由Clang实现的。例如,在C模式下,GCC支持嵌套函数,并具有允许在结构中使用VLA的扩展。

© www.soinside.com 2019 - 2024. All rights reserved.