Initialize an "eye" (identity) matrix array in C -
int eye[3][3] = { { 1,0,0 }, { 0,1,0 }, { 0,0,1 } };
is there shorter way initialize it? it's regular there must smarter way initialize it, if it's more 3x3, 10x10 or more.
in c99 can write:
int eye[][3] = { [0][0] = 1, [1][1] = 1, [2][2] = 1 };
all other elements zeroed, compiler figures out size of array you. don't skip second size (3).
btw. in code don't have use double braces, fine too:
int eye[3][3] = { 1,0,0, 0,1,0, 1,0,1, };
in c99 can leave trailing comma, symmetry , future refactorings
other solutions require write code, may indeed save time/space in file. note way you're splitting declaration , "initialization", in case of e.g. globals can make difference.
Comments
Post a Comment