Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!hplabs!hpda!hpcupt1!hpisod2!decot From: decot@hpisod2.HP.COM (Dave Decot) Newsgroups: comp.lang.c Subject: Re: The D Programming Language (was: Still more new operators) Message-ID: <2550047@hpisod2.HP.COM> Date: 1 Mar 88 03:45:27 GMT References: <11702@brl-adm.ARPA> Organization: Hewlett Packard, Cupertino Lines: 87 Array first-class-ness and aggregate constants could be easily provided within C (not that I want to discourage D-zigners; it's a meritorious idea). The basic ideas are that "a[]" is an array lvalue, and that aggregate constants are natively typeless and must always be either cast or assigned to the appropriate type. Two examples follow. (Watch out for the extensions to printf(3S) and scanf(3S) for array handling.) I will explain any of this if desired. EXAMPLE 1 int thing(i, a, b)[2] int i, a[2], b[2]; { int val[2]; val[0] = a[i] - b[0]; val[1] = a[i] - b[1]; return (val[]); } main() { typedef int PAIR[2]; char *message = "END-OF-EXAMPLE"; PAIR p1, p2, p3[2]; p1[] = {2, -3}; printf(p1: "%(2)4d\n", p1); p2[] = {1, 7}; printf("p2: %(2)4d\n\n", p2); p3[0][] = thing(0, p1[], p2[]); p3[1][] = thing(1, p1[], (PAIR) {1, 7}); printf("p3: %(2; )(2, )d\n\n", p3); printf("%(* )c\n", strlen(message), message); printf("%(*:-])c\n", strlen(message)*2/3, (char *)NULL); } prints p1: 2 -3 p2: 1 7 p3: 1, -5; -4, -10 E N D - O F - E X A M P L E :-]:-]:-]:-]:-]:-]:-]:-]:-] ANOTHER EXAMPLE main() { int array[10][10]; int array2[100][10] = {0}; /* fills entire auto array with 0s */ int row; scanf("%(10 )(10 )d", array); /* reads free-format 10x10 array */ /* copy array into top 10 rows of array2 */ for (row = 0; row < 10; row++) array2[row][] = (int [100]) array[row][]; /* cast is not needed */ reduce( (int [100][100]) array2[], 10); /* this cast is required */ for (row = 0; row < 10; row++) /* copy the rows back */ array[row][] = array2[row][]; printf("%(10\n)(10 )6d\n", array); /* display square array */ } reduce(a, n) int a[100][100]; int n; { /* ... */ }