Don’t call me pedantic!

A few weeks ago in a class, the professor mentioned that C does not support nested functions. He wrote an example on the board that he claimed would not compile.

A student quickly typed up the program on his laptop and said, “GCC compiled it just fine.” The professor replied, “Well, I’ve never heard of that. It must be a compiler feature unless they changed the standard.”

The student then said, “Well, I added -ansi and GCC still compiles it.” The professor caved in — “I guess they changed the standard recently.”

I was sure they most certainly didn’t. This incident bothered me since I knew nested functions couldn’t possibly be in C99. When I got home I reproduced the scenario, and sure enough, the student was right. GCC was compiling completely invalid syntax even with the “-ansi” setting. After digging through the documentation, I was able to find two things:

  • GCC has its own custom extensions to the C language, which includes nested functions.
  • This custom extension is enabled by default even if you choose a language specification where it does not exist.

As if that weren’t strange enough, GCC’s option to disable its custom additions appears to be called “-pedantic.” Uh, I don’t think it’s pedantic if I want the language to conform to the actual standard. As much as I like GCC and its custom extensions (many of which are pretty cool), they should be opt-in, not opt-out, in compliance modes.

I frequently see people say “Microsoft’s stupid compiler doesn’t conform to ANSI.” Well, after this, I’m not so convinced GCC is innocent either.

That said, GCC’s nested function feature and its implementation are both very cool. Taking a look at the disassembly, it does run-time code generation on the stack. Simple example:

Select All Code:
include <stdio.h>
 
int blah(int (*g)())
{
    g();
}
 
int main()
{
    int i = 0;
 
    int g()
    {
        i++;
    }
 
    g();
    blah(g);
 
    printf("%d\n", i);
}

15 thoughts on “Don’t call me pedantic!

  1. Byron

    Hello there, You have done a fantastic job. I will definitely digg it and in my view
    suggest to my friends. I’m sure they will be benefited from
    this web site.

  2. ルイヴィトン財布偽物

    株式会社 スーパーコピーブランド激安市場

    ブランドコピー、ロレックスコピー、オメガコピー、ウブロコピー、ルイヴィトンコピー、シャネルコピー、グッチコピー、
    スーパーコピーなどです。バッグ、財布、キーケース、時計、ジュエリー、マフラー、ストール、靴下、小件などあります
    1.当社の目標は最高のインターネットサービスご提供することです.弊社は24時間営業、年中無休.
    2.品質を重視、納期も厳守、信用第一は当社の方針です.
    3.日本には無い商品,日本では高価な商品,弊社のない商品,取引先を代理して製造会社を連絡することができる.
    4.弊社長年の豊富な経験と実績があり.輸入手続も一切は弊社におまかせできます.ご希望の商品を責任を持ってお届けします

    是非ご覧ください!

    休業日: 365天受付年中無休

  3. Boyce Schnake

    Thank you for sharing superb informations. Your web-site is very cool. I am impressed by the details that you have on this blog. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found just the info I already searched everywhere and simply could not come across. What a perfect web site.

  4. canna line

    Excellent items from you, man. I’ve take into account your stuff prior to and you are just extremely great. I really like what you have received here, certainly like what you are saying and the way in which during which you say it. You’re making it entertaining and you continue to take care of to stay it smart. I can not wait to learn far more from you. That is really a wonderful web site.

  5. home page

    excellent points altogether, you just gained a new reader. What would you recommend in regards to your post that you made some days ago? Any positive?

Comments are closed.