News for hackers. Stuff that matters.
Re:Pascal at Apple by kkylin on Saturday July 22, 2017 @12:01AM (#14825334)
Off-topic, but nested functions are one of my favorite gcc extensions.
Re:Pascal at Apple by WalterBright on Saturday July 22, 2017 @05:17AM (#14826179)
I discovered with C and C++ compilers, if an extension was added that was not in the Standard, nobody would use it - not even the people who requested the extension. It wasn't like the Pascal community, where nobody would use the compiler unless it had a boatload of extensions :-)
Re:Pascal at Apple by pjmlp on Saturday July 22, 2017 @07:14AM (#14826583)
They tried to fix that with ISO Extended Pascal, but by then compatibility with Turbo Pascal extensions was more relevant.
Re:Pascal at Apple by kkylin on Saturday July 22, 2017 @10:53AM (#14827492)
I think you're onto something (about C extensions). There was a time, before clang became default on osx, when Apple deprecated nested functions (and perhaps others) in their version of gcc, and afaik no one complained. So I may well be one of the very few. Oh well.
Re:Pascal at Apple by anthay on Sunday July 23, 2017 @04:39AM (#14831419)
In the past I've sometimes used standard C++ local structs to nest functions. E.g.:

    int f()
    {
        struct local {
            static int nested_func()
            {
                return 123;
            }
        };

        return local::nested_func();
    }
Re:Pascal at Apple by WalterBright on Sunday July 23, 2017 @08:04PM (#14835047)
I've done that, too. It's clumsy and only does half the job (doesn't provide access to locals). At some point one just gets tired of the workarounds :-)
Re:Pascal at Apple by anthay on Tuesday July 25, 2017 @08:53AM (#14847298)
It's probably a bit late for this reply, but... Another clumsy workaround is to use operator(). Again, standard C++ and this one has access to local variables:

    int g()
    {
        int x, y;

        struct local {
            int & a_;
            int & b_;
            local(int & a, int & b) : a_(a), b_(b) {}
        
            int operator()()
            {
                return a_ + b_;
            }

        } nested(x, y);

        x = 99; y = 1;
        return nested();
    }

    assert(g() == 100);