Malcolm said:
Mike Wahler said:
void bar(void)
{
int arr[100];
foo(arr);
}
calls foo with a pointer to an array of integers.
Wrong. Calls 'foo()' with a pointer to an 'int'.
(type 'int*'). Pointer-to-int and pointer-to-array-of-ints
are not the same type.
int *p; /* pointer to int */
int (*pa)[100]; /* pointer to array of 100 ints */
That's the difference between C usage and English usage.
Lacking explicit qualification to the contrary,
C meanings take precedence here.
C doesn't
distinguish between a pointer to an area of memory containing a single
integer, or an area containing an array of integers.
Actually, yes it does. The types are not the same (nor need
their sizes be the same) Also, the types yielded by dereferencing
those two different type pointers are not the same, nor are their
sizes -- except in the case of a pointer to an array of one element
-- that is, their sizes would be the same, but their types still
would not).
It is correct to say
that bar receives a pointer to 100 integers,
No it's not. The name of an array, when passed to a function,
decays to a pointer to its first element. The type passed
is 'pointer-to-array-element-type'.
and since they are in an array,
That doesn't matter.
it is also correct to say that it receives a pointer to an array of 100
integers.
No, it is not correct. Again:
Pointer to array of 100 ints:
int (*pa)[100];
Pointer to int:
int *p;
Those two types are *not* the same. If they were, then this
would be valid:
void foo(int (*arg)[100])
{
}
void bar(void)
{
int arr[100];
foo(arr);
}
... but it doesn't.
However it is also correct to say that this is false.
Huh?
The syntax is horrible
A matter of opinion. I have no trouble with the syntax.
and they have few real applications (most 2d arrays
have at least one variable dimension).
Subjective assesment. You're limiting your view to
only those applications you can conceive. Your phrase
'most 2d arrays' is without context, so hasn't any
useful meaning..
Your code will be hard to read
Subjective opinion again.
and
the use of multi-dimension constructs will suggest to the reader that you
don't have much experience with C.
That made me laugh out loud.
Consequently when bugs appear in your
code,
So you're saying that simply by using a 2d array has
the effect of creating bugs? Oh, please.
as happens to us all from time to time,
Yes, being human, everyone makes mistakes occasionally
(or perhaps even frequently). But the use of a particular
(valid) construct is not a direct cause. What create bugs
are carelessness and/or insufficient knowledge.
it will be re-written from
scratch instead of mended.
Depending upon how 'broken' a program is, sometimes
a rewrite is indeed the superior choice. This has
indeed been the case a few times in my experience
(both with my own code, and that of others). But
the cause was never the use of a valid language
construct. Sometimes I'll see that a particular
construct was not the best solution, but that's
a case of poor design, not 'bugs'.
This will cause your employers to question the
value of your continued employment,
Any employer/client I might wish to work with will
judge my value by that of what I produce. The value
of those products is determined by a consumer market,
not anyone's opinions about whether I understand C or not.
and in a tight market because of
outsourcing to India you will not be able to find another job,
Being an unabashed capitalist, I gladly welcome competition
from anyone, anywhere. I don't blame others for any problems
I might have, I take responsibility for solving them.
and if you
have few skills outside It you will be forced to take a position at Burger
King where the other staff will laugh at you for being too middle class,
so
you will leave and hit the streets, and end your days as a tramp or
beggar.
There is nothing dishonorable about working in the food service
industry, or any other value-producing profession. Nor do I allow
derision of others to dictate my actions.
You sir, are a snob.
-Mike