Frage zu Bedingungen
-
SAKRA SAKRA... Das Theme ist ja hochinteressant...
Ist folegendes dann richtig??? Also man kann das bestimmt schönter, besser machen...
void fill3(int (*arr)[3], int zeilen){ //ptr 2 an array of 3 int int i, j; int value=15; for(i=0; i<zeilen; i++){ for(j=0; j<3; j++){ //arr[i][j]=value++; (*arr)[j]=value++; //gibt es eine Variante ganz ohne Index???? } arr++; } }
...Das waren jetzt viele Fragen, bin mal gespannt...
-
typedef struct {int a[3];} A3; /* Hilfstyp für blockweise int-Zuweisung */ void fill3(int (*arr)[3], int zeilen) { A3 a={1,2,3}; while( zeilen-- ) *(A3*)arr[zeilen]=a; } void fill4(int (*arr)[3], int zeilen) { A3 a={1,2,3}; while( zeilen-- ) *(A3*)*arr++=a; /* ganz ohne 'Index' */ }
-
Wutz schrieb:
typedef struct {int a[3];} A3; /* Hilfstyp für blockweise int-Zuweisung */ void fill3(int (*arr)[3], int zeilen) { A3 a={1,2,3}; while( zeilen-- ) *(A3*)arr[zeilen]=a; } void fill4(int (*arr)[3], int zeilen) { A3 a={1,2,3}; while( zeilen-- ) *(A3*)*arr++=a; /* ganz ohne 'Index' */ }
Ahhh...ja.
Nicht von schlechten Eltern. Ich bin mir nicht ganz sicher ob ich das jetzt so kapiert habe...(A3)... =>castet das arr??
-
So ein Cast ist üblich für die struct-content-copy Zuweisung in ANSI C.
Mit C99 und compound statements ginge das nochmal kürzer:void fill4(int (*arr)[3], int zeilen) { while( zeilen-- ) *(A3*)*arr++=(A3){1,2,3}; /* ganz ohne 'Index' */ }
-
Gehört der * nach (A3*) noch zum cast?
Also
(A3)*arr++=a;
------^ der hier? so quasi der Wert von A3 castet arr ist a ??