lang-c icon indicating copy to clipboard operation
lang-c copied to clipboard

Internal functions are not accepted

Open omarandlorraine opened this issue 3 years ago • 1 comments

I've found this kind of code which is accepted by Clang and GCC, but not by lang-c.

int fn() {
        int ifn() {
                return 5;
        }
        return ifn();
}

fn is a function having an internal function, named ifn. ifn is only in scope inside the body of fn. This is not standard C, but a GNU extension. I don't think it's in ANSI C or ISO C99, or K&R, or anything like that. So I am not sure if we want or need to accept this kind of code in lang-c.

I'm getting this error message:

SyntaxError(SyntaxError { source: "# 0 \"c/fninfn.c\"\n# 0 \"<built-in>\"\n# 0 \"<command-line>\"\n# 1 \"/usr/include/stdc-predef.h\" 1 3 4\n# 0 \"<command-line>\" 2\n# 1 \"c/fninfn.c\"\nint fn() {\n int ifn() {\n  return 5;\n }\n return ifn();\n}\n", line: 8, column: 12, offset: 156, expected: {";", "asm", "(", "[", ",", "="} })

What do you think?

omarandlorraine avatar Nov 06 '22 21:11 omarandlorraine

Sure, it would be nice to add support for this extension. GNU extensions are definitely in the scope for lang-c, there is already support for a small number of them.

vickenty avatar Nov 06 '22 22:11 vickenty