Cé ååç §æ¼ç®åã®èå³æ·±ãä»æ§
open-std.org ã®C99 Rationaleãèªãã§ãã¦ãèå³æ·±ãä¸ç¯ãçºè¦ã
6.5.2 Postfix operators 6.5.2.1 Array subscripting
The C89 Committee found no reason to disallow the symmetry that permits a[i] to be written as i[a].The syntax and semantics of multidimensional arrays follow logically from the definition of arrays and the subscripting operation. The material in the Standard on multidimensional arrays introduces no new language features, but clarifies the C treatment of this important abstract data type.
ãããã©ãã (2ch ã ã£ãã v*** å çã ã£ããå¿ãããã©) ã§è¦ãè¨æ¶ããè¦ã¯ã
#include <stdio.h> int main() { int i = 1; char c = i["test"]; printf("%c\n", c); return 0; }
ãããã¨ã©ã¼ãªãã³ã³ãã¤ã«ã§ãã¦ããããå®è¡ããã¨ã¡ããã¨
e
ã¨è¡¨ç¤ºãããã¨ãã話ãC99 ããå°å ¥ãããè¤åãªãã©ã«ã使ãã°ããã£ã¨ãã¢ããªãã¾ãã
#include <stdio.h> int main() { int i = 1; struct moo { int a; }; struct moo m = i[(struct moo[3]){ { 1 }, { 2 }, { 3 } }]; printf("%d\n", m.a); return 0; }
ããããã¯ãä½èªããããã¾ããããã¡ãªã¿ã«ãã®æ¸ãæ¹ã§ void * ã dereference ããã¨ã©ããªããã
#include <stdio.h> int main() { int i = 1; void *a = "abc"; char c = i[a]; printf("%c\n", c); return 0; }
moriyoshi% gcc -std=c99 -Wall -o test test.c test.c: In function 'main': test.c:7: warning: dereferencing 'void *' pointer test.c:7: error: void value not ignored as it ought to be
ã¨ãã¡ããã¨ã¨ã©ã¼ã«ãªãããã§ãã