[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: const char* typedefs
- From: Sean Conner <sean@...>
- Date: Wed, 7 Feb 2018 22:00:13 -0500
It was thus said that the Great Paige DePol once stated:
> >> I don't know what you mean by "the whole 2[pa] bit" though, can you explain?
> >
> > #include <stdio.h>
> >
> > char *a[] = { "zero" , "one" , "two" , "three" };
> >
> > int main(void)
> > {
> > puts( a[0] );
> > puts( 1[a] );
> >
> > putchar( 2[ 3[a] ] ); putchar('\n');
> > putchar( 2["0123"] ); putchar('\n');
> >
> > return 0;
> > }
> >
> > Valid. And it runs without error.
>
> What the heck is this voodoo magic? I have never seen this syntax before.
It comes because array syntax is "syntactic surgar." So let's take a[1].
This is
a[1] = *(a + 1)
And because addition is commutative, you also have
a[1] = *(1 + a)
which, when you adjust the left side:
1[a] = *(1 + a)
And viola! Voodoo magic.
-spc
[1] An example, not a real foot note [2].
[2] If there were real foot notes, there would be foot notes. [3]
[3] Fnord.
- References:
- const char* typedefs, Paige DePol
- Re: const char* typedefs, Forrest Christian (List Account)
- Re: const char* typedefs, Dirk Laurie
- Re: const char* typedefs, Paige DePol
- Re: const char* typedefs, Sean Conner
- Re: const char* typedefs, Paige DePol
- Re: const char* typedefs, Sean Conner
- Re: const char* typedefs, Paige DePol
- Re: const char* typedefs, Sean Conner
- Re: const char* typedefs, Paige DePol