GCC knows how big an array is:
jake$ cat > arrsizetest.c
#include <stdio.h>
int main()
{
int a[50];
printf("sizeof a == %d\n",sizeof(a));
return 0;
}
jake$ gcc arrsizetest.c
jake$ ./a.out
sizeof a == 200
jacob
On Sat, 7 May 2005, Thomas Davie wrote:
No, it introduces a variable of type "array of 50 ints", which can be
converted to "pointer to int".
It matters when you make a pointer of such arrays, an array of such
arrays, or sizeof such array. In C++ the size can be matched by
template parameter, and you can have separate overloadings for
separate array sizes.
I'm not familiar with your C++ example (not being familiar with C++), but I
think that it's a bit of a stretch of the imagination to say that C
"introduces a variable of type "array of 50 ints"", the fact that this is now
an array of 50 integers is never checked at any point in the compilation or
run, and I'm not sure it can be even if K&R had wanted to. If I'm thinking
straight then *any* array definition merely gets re-written to a memory
allocation of the relevant amount of ram, and beyond this point it is forever
of type "pointer to <array content type>".
As an example:
int bobsArray[5];
bobsArray[6] = 23;
is not badly typed ? it is merely a badly broken program.
Bob
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe