A
Anonymous 7843
PL/I.
Bliss/10Anonymous said:PL/I.
Bliss/10
why always create a new incompatible language when you
just have some small improvements ?
you need a new compiler and your old programs will
no longer run.
C said:Bliss/10
So, who will be the first to write that useful command line utility
converting occurrances of A[x,y] to A[x][y]...
>Anyone who suggests that C indexes should start at 1,
>doesn't even understand this much: the idea that their
>opinion on C might have merit is laughable.
>Similarly, since in the 4-D array expression
> a[c][d][e]
>one can't know, without studying the declarations,
>whether 'a' is an array of pointers to arrays
>of pointers, a pointer to an array of pointers
>to arrays, or one of several other possibilities,
>the idea of obfuscating this further by writing
> a[b,c,d,e]
>suggests lack of understanding. (We're sorry if
>'[' and ']' are hard to produce on German keyboards
>but I'm sure there's workarounds for that.)
>(Do any other languages, besides C++ and others that
>model their syntax on C, have a similar elegant
>array/pointer model?)
>
>Finally, it shows grave confusion to suggest that
>someone who prefers to see C syntax when they're reading
>a C program should simply run 'cc -E'. We all look
>at intermediate compilation results when there's a
>reason, but viewing unobfuscated source shouldn't be
>one of them. To give only one of the most obvious
>objections, on all compilers I've tried 'cc -E' will
>remove comments; did OP overlook this?
>No one claims the C language is a perfect panacea, but
>it has an enviable elegance. Novices should devote
>themselves to grasping that elegance before offering
>"improvements."
></diatribe>
James Dow Allen said:(e-mail address removed) wrote: [...]
<diatribe>
C is a victim of its own success!
I don't think Fortran programmers ever say
"Let's make our language more like Pascal."
Ones that might ... switch to Pascal!
One of the most elegant features of C is the
identity between the referencing of pointers
and array elements. Yet this seems to be
consistently confused by novices! Why? It
can't be that C is "too complicated" -- C is
based on a tiny set of elegant principles.
I think the problem is that novices can't
believe such a powerful language is *so simple*!
Viewed in total isolation, the question of whether
to start array indexes at 0 or 1 may be a legitimate
open question, but in C the question answers itself
once one notices that the following expressions
(outside sizeof, etc.) must be identical in C:
*p
*(p+0)
0[p+0]
p[0+0]
p[0]
Anyone who suggests that C indexes should start at 1,
doesn't even understand this much: the idea that their
opinion on C might have merit is laughable.
Finally, it shows grave confusion to suggest that
someone who prefers to see C syntax when they're reading
a C program should simply run 'cc -E'. We all look
at intermediate compilation results when there's a
reason, but viewing unobfuscated source shouldn't be
one of them. To give only one of the most obvious
objections, on all compilers I've tried 'cc -E' will
remove comments; did OP overlook this?
No one claims the C language is a perfect panacea, but
it has an enviable elegance. Novices should devote
themselves to grasping that elegance before offering
"improvements."
</diatribe>
James Dow Allen wrote: [...]suggests lack of understanding. (We're sorry if
'[' and ']' are hard to produce on German keyboards
but I'm sure there's workarounds for that.)
yes. Give a link to the utility I'm looking for.
It's called a C compiler with digraph support. <: and :> will beKeith said:James Dow Allen wrote:
[...]
suggests lack of understanding. (We're sorry if
'[' and ']' are hard to produce on German keyboards
but I'm sure there's workarounds for that.)
yes. Give a link to the utility I'm looking for.
As far as I know, it doesn't exist. Sorry.
I don't think Fortran programmers ever say
"Let's make our language more like Pascal."
Ones that might ... switch to Pascal!
Keith said:And we wonder why people think comp.lang.c is a hostile newsgroup.
There are applications in which 1-based arrays are more convenient
than 0-based arrays.
1-based arrays
are much more convenient for some mathematical algorithms (see
_Numerical Recipes in C_, which I cited upthread).
James Dow Allen wrote:
...Anyone who suggests that C indexes should start at 1,
doesn't even understand this much: the idea that their
opinion on C might have merit is laughable.
I didn't suggest, that indices should start at 1,
starting at 0 is fine, but
I just suggested that e.g. int A[n]; should reserve n+1
memory-cells instead of n. Or that we have a preprocessor utility
to change int A[n] into int A[n+1] before the compiler
gets it from batch file or in a child process.
Very often you are using A[n] and want it to hold integers 1..n,
with or without 0.
I guess, this is a quite common error for C-programmers,
Keith Thompson wrote:
But this is a bad argument. I am initimately familiar with the book
... the use of 1 based arrays was for ease of translation from
algorithms that had been coded in Fortran
Yes not letting the arrays be anything other than 0 based is a weakness
of C.
Mark said:James Dow Allen wrote:
...
Anyone who suggests that C indexes should start at 1,
doesn't even understand this much: the idea that their
opinion on C might have merit is laughable.
I didn't suggest, that indices should start at 1,
starting at 0 is fine, but
I just suggested that e.g. int A[n]; should reserve n+1
memory-cells instead of n. Or that we have a preprocessor utility
to change int A[n] into int A[n+1] before the compiler
gets it from batch file or in a child process.
Why? Because you're incapable of recalling that the first element of
an array is at zero off set from the start? Because you're lazy?
Very often you are using A[n] and want it to hold integers 1..n,
with or without 0.
I guess, this is a quite common error for C-programmers,
Only when they're beginners. It must be practically the first lesson
one learns about arrays.
Mark McIntyre said:(i'm not convinced he did, but...)
More accuirately, tehy were coded thus because the writers were
Fortran programmers who knew very little C, and seemingly lacked the
skills to reimplement their algos in C. So instead they literally
xlated the fortran, then wrote helper functions to mangle the C arrays
into fortran ones... yeuch.
Sure, there are sometimes needs for arrays not starting at one, or for
sparse arrays. C happens not to have native support for that, well
excuse me but it also doesn't have native support for fast fourier
transforms or gaussian integrals or threads, all of which would also
be useful too. Is their lack a weakness?
Keith said:James Dow Allen said:Viewed in total isolation, the question of whether
to start array indexes at 0 or 1 may be a legitimate
open question, but in C the question answers itself
once one notices that the following expressions
(outside sizeof, etc.) must be identical in C:
*p
*(p+0)
0[p+0]
p[0+0]
p[0]
They *must* be identical because existing code would break if they
weren't. That doesn't necessarily imply that a C-like language
couldn't be devised in which they aren't identical, and arrays behave
differently.
Other that the "elegance" part, I agree.
James Dow Allen said:Keith Thompson wrote: [...]They *must* be identical because existing code would break if they
weren't. That doesn't necessarily imply that a C-like language
couldn't be devised in which they aren't identical, and arrays behave
differently.
Given that the array/pointer relationship is essential
to C, I assume what you're suggesting is that
C could have been consistently defined so that the
expression (*p) evaluates to (p[1]). Now (*(p+6))
would be (p[7]) and so on. Did you have something
else in mind?
"Elegance" is hard to define and best grasped with
examples. The property of ordinary expressions that
*(p+6) is equivalent to p[6]
would be devastatingly less elegant if replaced with
*(p+6) is equivalent to p[7]
Are you sure? The standard (7185) says these are just 'abbreviations'I'll rephrase. C has multidimensional arrays. They're implemented
as, and are indistinguishable from, arrays of arrays.
There are other languages that make the distinction. For example,
Pascal has both multidimensional arrays:
arr1: array[1..10,1..10] of float;
and arrays of arrays:
arr2: array[1..10] of array[1..10] of float;
with distinct syntax for indexing into them (arr1[x,y] vs. arr2[x][y])
and different semantics (you can easily extract a one-dimensional
array from an array of arrays, but not from a multidimensional array).
So yes, C has multidimensional arrays in much the same way that it has
pass-by-reference: it lets you build it explicitly on top of other
constructs. I'm not convinced the statement about multidimensional
arrays in 6.5.2.1 is strictly necessary (I think it probably follows
from other statements in the standard), but I have no problem with it
being re-stated.
Concur.
[snip]
[...]Dave Thompson said:Are you sure? The standard (7185) says these are just 'abbreviations'I'll rephrase. C has multidimensional arrays. They're implemented
as, and are indistinguishable from, arrays of arrays.
There are other languages that make the distinction. For example,
Pascal has both multidimensional arrays:
arr1: array[1..10,1..10] of float;
and arrays of arrays:
arr2: array[1..10] of array[1..10] of float;
with distinct syntax for indexing into them (arr1[x,y] vs. arr2[x][y])
and different semantics (you can easily extract a one-dimensional
array from an array of arrays, but not from a multidimensional array).
(sugar) for the array-of-array form, and I don't recall original (J&W)
as being any different in this area.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.