Iso c forbids nested functions - pedantic




















The code has invalid syntax and in such cases compiler parsers can make strange assumptions or guesses about what was intended. Unless you want to analyse your compiler's parser it isn't something that is really worth worrying about. A Pascal compiler I know stops compiling after the 1st error encoutered. It might have a good reason. I guess: you're using GCC, GCC can compile nested functions, and the syntax errors have confused it into thinking that's what you've written.

ANSI C forbids braced-groups within expressions. Newbie: separate big. Order of evaluation of nested function arguments. Nested function prototypes: bug in VAX C v2. Active 3 years, 3 months ago. Viewed 6k times. Improve this question. Mayank Verma.

Mayank Verma Mayank Verma 4 4 silver badges 18 18 bronze badges. Adding -pedantic -Werror should fix that. Add a comment. Active Oldest Votes. Add -pedantic and -Werror to the command line. And there's also a different option that gives pedantic errors: -pedantic-errors Give an error whenever the base standard see -Wpedantic requires a diagnostic, in some cases where there is undefined behavior at compile-time and in some other cases that do not prevent compilation of programs that are valid according to the standard.

Improve this answer. Community Bot 1 1 1 silver badge. Jonathan Leffler Jonathan Leffler k gold badges silver badges bronze badges. This is something that I stumbled on when I added -pedantic to my default compile string. Might want to emphasise and explain your usage of -Wall -Wextra. These cause the compiler to report various concerns that it is not configured to by default.

Not all of these are pertinent to avoiding gcc extensions, but they are concerns that either indicate bugs suspicious conversions, etc or which won't work as intended with other compilers. If -Werror does not cause termination on warning, a deliberate policy of "don't accept code that triggers warnings" will. This still doesn't disable gnu extensions, except those that are related to syntax.

I don't see how this answers the question. Turning all warnings into errors is not the same as disabling GNU extensions. Of course, it allows what we could call nested functions — but I believe this isn't the correct terminology. Here we have already two levels, and I suppose there's no limits. You can also use let … in , even if this is an expression see Let vs. Where , or mix let … in and where as in the next example:. In C, we can't: we need to be more explicit and write other functions.

In the gist I've put it in its own file. If the language allows nested functions and has also lambda, which one to use? It depends. An example of a language that has lambdas and also allows nested functions defines is Python. I don't know if those def s can be considered functions or they are methods of an anonymous class, like in Ruby if I remember correctly. Maybe using lambdas is better.

But Python's lambda must be defined as expressions, so we need to write a thing like this:. In Ruby it is possibile to nest def s, but the nested def behaves almost like a function defined outside.



0コメント

  • 1000 / 1000