News for hackers. Stuff that matters.
Re:A nice, little known C feature: Static array indices in p... by rwmj on Monday February 18, 2013 @03:56PM (#5240583)
Larry Wall (author of Perl) used this as an argument for "sigils", that is, putting $/@/% in front of every variable.

http://stackoverflow.com/questions/1091634/why-do-perl-varia...

(I merely state this as fact and offer no judgement!)

Re:A nice, little known C feature: Static array indices in p... by drivers99 on Monday February 18, 2013 @05:53PM (#5241334)
Deleted my previous comment because it was wrong (I was saying that it didn't help with the names of subroutines). It appears you can even have subroutines named after keywords, but only as long as you put "&" in front of it when you call it:

    sub while
    {
        print "It works!\n";
    }

    &while();
I guess it is still the case that you can break perl code by adding keywords, if it collides with a subroutine that is called with the "&" symbol. Seems most code doesn't use "&" though, but it's a relatively quick fix.
Re:A nice, little known C feature: Static array indices in p... by leviathan on Monday February 18, 2013 @06:01PM (#5241384)
Calling a sub with & has a special meaning, it exposes the current argument list @_ to the called sub. That's why you don't see it in most code.
Re:A nice, little known C feature: Static array indices in p... by drivers99 on Tuesday February 19, 2013 @11:59AM (#5245388)
I did not know that. Interesting. However, it only works if you call the sub without parentheses like this: &foo

Calling it with parentheses like &foo() would make @_ empty inside of foo. (Or if you said &foo("whatever") it would pass that as @_ instead.)

    sub while
    {
            print "@_\n";
            &foo();
    }

    sub foo
    {
            print "@_\n";
    }

    &while("a","b","c");
produces:

    a b c
    (blank line)
as the output, and

    sub while
    {
            print "@_\n";
            &foo;
    }

    sub foo
    {
            print "@_\n";
    }

    &while("a","b","c");
produces:

    a b c
    a b c 
as the output. At any rate, back to the original topic: it still doesn't prevent new keywords from potentially colliding. Oh well.
Re:A nice, little known C feature: Static array indices in p... by tolmasky on Monday February 18, 2013 @09:13PM (#5242195)
I prefer the objective-c method of putting @ in front of every keyword.
Re:A nice, little known C feature: Static array indices in p... by dietrichepp on Tuesday February 19, 2013 @02:37AM (#5243140)
Well, I might be upset if this were true for all keywords.

    @static @inline @unsigned @int ilog2(@unsigned @int x)
    {
        @for (@unsigned @int i = 0; i < 32; i++)
            @if ((x >> i) == 0)
                @return i;
        @return 32;
    }
I'm a bit dizzy looking at that code, let me sit down for a moment.
Re:A nice, little known C feature: Static array indices in p... by redial on Tuesday February 19, 2013 @03:41AM (#5243319)
I believe the @ is used only by the obj-c keywords and not the ones from C. So it'll be something more like this

    @autoreleasepool{
        for (int index = 0; index < 100; index++){
            int error = [MyObject performSelector:@selector(addCoolFilterToImage:)];
            if (error) {
                return 32;
            }
        }
    }
Re:A nice, little known C feature: Static array indices in p... by dietrichepp on Tuesday February 19, 2013 @05:52AM (#5243644)
Yeah, that was kind of my point.