what does 'covariant arrays' mean?

T

Tydr Schnubbis

I've read an interview with Brian Kernighan here:
http://www-2.cs.cmu.edu/~mihaib/kernighan-interview/index.html.
The interviewer asks him, among other things, about the weaknesses of C.
This is from one of the questions:

'...but also the researchers point some of its weaknesses (like the
arrays which are covariant and they shouldn't be).'

There's no explaination of what a covariant array is. I've found some
explainations of what this means in a Java context, but can anyone
explain to me what this means in the C language, and why this is
considered a weakness?

Tydr
 
B

Ben Pfaff

Tydr Schnubbis said:
I've read an interview with Brian Kernighan here:
http://www-2.cs.cmu.edu/~mihaib/kernighan-interview/index.html.
The interviewer asks him, among other things, about the weaknesses of C.
This is from one of the questions:

'...but also the researchers point some of its weaknesses (like the
arrays which are covariant and they shouldn't be).'

There's no explaination of what a covariant array is. I've found some
explainations of what this means in a Java context, but can anyone
explain to me what this means in the C language, and why this is
considered a weakness?

C doesn't have covariant arrays, because C doesn't have
covariance. Covariance and its sister concept, contravariance,
apply only (as far as I know) to data types arranged in a
hierarchy, as is most often seen in inheritance within
object-oriented type systems. C doesn't have any such hierarchy
of types, so the concept of covariance doesn't arise. C++ and
Java do have inheritance hierarchies and thus questions about
covariance become interesting. In particular, C++ does not
support covariant arrays, but Java does.
 
R

Régis Troadec

"Tydr Schnubbis" <[email protected]> a écrit dans le message de

Hi,
I've read an interview with Brian Kernighan here:
http://www-2.cs.cmu.edu/~mihaib/kernighan-interview/index.html.

Interesting !
The interviewer asks him, among other things, about the weaknesses of C.
This is from one of the questions:

'...but also the researchers point some of its weaknesses (like the
arrays which are covariant and they shouldn't be).'

You did'nt quote all the text:

The interviewer asks: " I have a question about research in language design.
It's interesting for instance that Java is very much hyped and the community
is split among the merits and flaws of the language. The language has indeed
acquired some nice features proposed by researchers in the area (like
garabage collection), but also the researchers point some of its weaknesses
(like the arrays which are covariant and they shouldn't be. [...]"
There's no explaination of what a covariant array is. I've found some
explainations of what this means in a Java context, but can anyone
explain to me what this means in the C language, and why this is
considered a weakness?

It was about Java, not about C :). There are no covariant arrays in C.

Regis
 
R

Raymond Martin

There's no explaination of what a covariant array is. I've found some
explainations of what this means in a Java context, but can anyone
explain to me what this means in the C language, and why this is
considered a weakness?

Tydr

A covariant array is an array data structure where the elements can be of
differing type. I think it could be implemented indirectly through an array
of pointers in C (although this isn't the same really), or more far-fetched,
as an array of unions with a lookup array array that identifies the type of
each entry in the original array. If viewed as a weakness would it not just
be for the fact you need to code it yourself? Same type arrays are more
efficient for access since it's a scaled jump table of entries, when the
data types start changing you lose efficient register indirect access.
 
T

Tydr Schnubbis

It was about Java, not about C :). There are no covariant arrays in C.

Right you are. Sorry about that little blunder, I shall apply the
appropriate punishment to myself.

Tydr
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top