A container library for the C language

S

Seebs

jacob, my advice is that you don't waste your time responding to
this "tea leaf" troll. It's obvious he has some personal vendetta
against you, and nobody takes him seriously. Of course you can
reply if you like, but I suggest that it's not necessary.

Seconded. I apparently no longer have the troll in question killfiled, but
a quick review of his latest post suggests that he's almost certainly that
rarest of things, someone whose judgement is so consistently and reliably
bad that you can do well to treat his claims as evidence to the contrary.

If "tea leaf" were to claim that you could learn C from K&R, I'd have to
go review the book to see whether it had flaws I had somehow failed to
note in previous readings.

-s
 
D

Dag-Erling Smørgrav

Ed said:
A STL for C? Anyone going that far will undoubtedly choose C++, and not
some kludgy thing patterned after STL/C++brought down to C! Containers,
iterators, algorithms, a template system: it's ALREADY DONE IN C++.

So because C++ has containers, iterators and algorithms, we should not
use data structures, for loops or in fact anything that has any
observable effect on the state of the program?

C is still widely used in many environments, not just legacy code bases,
for a number of good reasons, and everyone who uses C needs containers,
and everyone who uses containers needs a way to iterate through them and
to operate on their contents. There are plenty of existing container
libraries for C (*BSD's <sys/queue.h> and <sys/tree.h>, for instance),
but if Jacob's library provides similar functionality with a cleaner
interface and / or better performance, I welcome it.

DES
 
D

Dag-Erling Smørgrav

If I use your library, I reference your "iList" extern variable
and the linker pulls in all the list methods in the vtable, even
though I only use a couple. I pay (in code size) for what I don't
use.

Can you quantify that cost?

DES
 
J

jacob navia

Pierre Asselin a écrit :
I can't read the .doc or the .odt but I had a quick look at
containers.h .

The .odt can be read using sun's open office product.
The .doc can be read if you download the (free) word reader
from Microsoft.
Suppose I need a simple linked list, nothing fancy.
If I use your library, I reference your "iList" extern variable
and the linker pulls in all the list methods in the vtable, even
though I only use a couple. I pay (in code size) for what I don't
use.


Maybe you haven't noticed but ALL libraries (either in C or in C++) are
the same. If you use
printf
you end up with the code of
log, exp, fgetc, and who knows what other functions printf uses.

The library is extremely small. If you use ALL containers, the cost is
64K in a 32 bit system. The specific cost of the list module is 4952
bytes.

Since the source code is provided, you are free to make a special
module where only the functions you need are implemented, and your code
will remain portable. You could trim down the whole list module to 4, or
5 functions and round 300-400 bytes, keepingg the same interface.

In the list.c module just erase the code of all functions you do not
need, leaving the empty functions:

int Add(List *l, void *data)
{
// erase all code and replace it with
return 0;
}
Maybe that's not a big cost, but your url says:
This page describes the work presented to the French C
standardization committee of the AFNOR to be included in
the next C standard.

If your interface becomes part of the standard library IMHO the
added cost is a problem. Maybe you can convince the committee that
the cost is acceptable in a hosted environment, but you will have
to argue the case. Or describe a low cost implementation, or modify
the interface.
The proposed interface allows for MANY implementations. I will add later
a "small list" implementation where
(1) there is no support for read only lists
(2) There is no vtable
(3) There is no heap support

This reduced list can be used in memory constrained implementations.
What is nice here is that THE SAME CODE will work in all other
implementations if you stick to the published INTERFACE.

The proposam can be customized for many completely different environments:

For heavy duty usage, the heap manager can be enhanced to keep terabytes
of data...
For small embedded systems the interface can be reduced to a bare
minimum
Lists with read only flag can be stored in read only memory...

Etc etc. ALL using the same interface, what makes the code that
USES the library PORTABLE.

That's the idea.


Thanks for your input

jacob
 
L

ld

I have been talking about this since quite a long time. It is (maybe)
time to offer the first release.

The URL is:http://www.cs.virginia.edu/~lcc-win32/container.html

There you can download a zip file containing
(1) The specifications of the library
(2) The source code of the sample implementation
(3) a makefile for Unix systems

Enjoy!

jacob

Hi Jacob,

I have been quickly through the doc and the code and have few general
remarks.

- The initiative is interesting, but it needs much more thinking if
you want something robust, flexible, scalable and efficient. It's a
strong requirement if you pretend to propose it for the standard.

- I found the code overcomplicated, probably very slow in few places
and buggy. In particular, your container store object by "value" and
you have iterators and direct element accessors. But you don't take
into account proper memory alignment nor proper semantic of copy (e.g.
you use memcpy and char array). You said to not pay attention to the
code so it's ok for me, but the choice of value vs reference semantic
will have a strong impact on your interfaces. It would be also nice to
split the file container.h into separate headers for each container
and to avoid the use of reserved identifier (_[AZ]).

- "Sub-classing" section has nothing to do with the term subclassing
in the literature. Your global tables should always be read-only for
many technical reasons related to types. It should also be thread safe
(or read-only) since this has a strong impact on your interfaces (BTW
I will never use a lib which is not thread safe). If you want to be
able to change behaviors at runtime, put some services to clone a
table first and allow to change the behavior in some controlled way.
Add rules for the management of their lifetime vs the set of objects
of this "dynamic" type (aka dynamic "classes" + ref counts).

- "Achieving container independence". The static type of your
container must be known by the compiler everywhere and hence are not
"interchangeable". As a consequence, containers types must be changed
for each args and locals declaration so it's only half interesting.
Considering the work increase (table, types, etc...), I am not sure
that its worth unless you improve it.

As a general remark, why not invest a bit more time in design before
writing hundreds of line of code? Why not design true reusable
interfaces (a-la-Java) or dictionary (a-la-Haskell) with dynamic
recovery (dynamic cast) which would allow you to really write generic
containers and iterators and decouple services from concrete
"classes"? With few lines of C and some conventions (like your i
prefix for interface), you could achieve a much better framework with
generic algorithms (e.g. generic sort). Since I have some experience
with OOP in C, I can give you some help depending on your objectives:
static (java-like) vs dynamic typing (objective-c like) interfaces/
protocols, support for inheritance (and thread-safety!), support for
meta-classes and meta-data, syntactic sugar of the DSL, expressive
power of the language features, support for multi-method and/or
delegation, etc... Of course, the more you want, the more work is
needed, but starting with generic interfaces and no inheritance can
lead to something very simple, efficient and generic enough if you
focus only on containers.

Cheers,

Laurent.
 
J

jacob navia

Dag-Erling Smørgrav a écrit :
Can you quantify that cost?

DES

4952 bytes

I answered him in another message in this thread about how he can reduce
that to the few functions he uses.
 
J

jacob navia

ld a écrit :
Hi Jacob,

I have been quickly through the doc and the code and have few general
remarks.

- The initiative is interesting, but it needs much more thinking if
you want something robust, flexible, scalable and efficient. It's a
strong requirement if you pretend to propose it for the standard.

Agreed

- I found the code overcomplicated, probably very slow in few places
and buggy.

Please tell me specific instances of "buggy"...
Thanks :)

In particular, your container store object by "value" and
you have iterators and direct element accessors. But you don't take
into account proper memory alignment nor proper semantic of copy (e.g.
you use memcpy and char array). You said to not pay attention to the
code so it's ok for me, but the choice of value vs reference semantic
will have a strong impact on your interfaces.

No, because you can just store a POINTER to your data, instead of the
data. Yes, I store the objects by value, but that "value" can be just a
pointer, and in that case you have a store by reference.

What is nice in this interface is that the decision of storing by value
or by reference can be done by the end user of the library and not by
the library writer.

It would be also nice to
split the file container.h into separate headers for each container
and to avoid the use of reserved identifier (_[AZ]).

That can be done but I think it uses up too much memory (neuron memory
in the user's brain). You would have to remember that

#include <list.h>
#include <arraylist.h>

or it was

#include <lists.h>
#include <arraylists.h>

???

Please let's simplify.
- "Sub-classing" section has nothing to do with the term subclassing
in the literature.

Sub-classing as is understood in event-oriented programming (Windows
system for instance) means to put yourself at a specific point in a
call-chain.

If function a calls function B that calls function C in a call chain,
you replace the function pointer in the vtable of B, and instead of
calling C directly you do something and THEN call C, or you call
C and THEN you do something, or you do not call C at all.
Your global tables should always be read-only for
many technical reasons related to types.

Can you elaborate?

Precisely the ability of replacing those function pointers with your own
is one of the advantages of my approach.


It should also be thread safe
(or read-only) since this has a strong impact on your interfaces (BTW
I will never use a lib which is not thread safe).

Globals are thread safe if you understand that a shared ressource
needs semaphore protection before you change it. But this is so basic I
surely do not need to explain it to you.

But maybe you mean something else? Please explain.

If you want to be
able to change behaviors at runtime, put some services to clone a
table first and allow to change the behavior in some controlled way.

Why?

People that want to change a global resource can do it themselves.

Suppose I follow your advice. Then all changes (and each change) to the
tables provokes a copy. That can be exactly what is needed in some
situation where you need to be able to go back and have the old
behavior, but could be just a waste if you do NOT want the old behavior
because you do not want to ever use it.

In the second case the wasted space is unavoidable if you have a
provided method.

Add rules for the management of their lifetime vs the set of objects
of this "dynamic" type (aka dynamic "classes" + ref counts).

Can you elaborate? I just do not understand what you mean here.

Thanks
- "Achieving container independence". The static type of your
container must be known by the compiler everywhere and hence are not
"interchangeable".

No. If you write:
Myobject->VTable->Add(Object, data);
instead of
iList.Add(Object,Data);

In the first case, the code REMAINS THE SAME if the object changes from
List to Array to whatever.
It is only in the second case that you need to change the code.
Using the FIRST syntax, even if it is more cumbersome, you have
container independence. Obviously the declaraion of "Object" must be
changed anyway.
As a consequence, containers types must be changed
for each args and locals declaration so it's only half interesting.

No, see above.
Considering the work increase (table, types, etc...), I am not sure
that its worth unless you improve it.

It doesn't need improvement.
As a general remark, why not invest a bit more time in design before
writing hundreds of line of code? Why not design true reusable
interfaces (a-la-Java) or dictionary (a-la-Haskell) with dynamic
recovery (dynamic cast) which would allow you to really write generic
containers and iterators and decouple services from concrete
"classes"?

Because I am not writing a full fledged framework for object oriented
programming in C but a container's library that should be extremely
small, stay within the language, and not invent a new way of doing OO
programming in C.

YOU have done that. That is a DIFFERENT project.

With few lines of C and some conventions (like your i
prefix for interface), you could achieve a much better framework with
generic algorithms (e.g. generic sort). Since I have some experience
with OOP in C, I can give you some help depending on your objectives:
static (java-like) vs dynamic typing (objective-c like) interfaces/
protocols, support for inheritance (and thread-safety!), support for
meta-classes and meta-data, syntactic sugar of the DSL, expressive
power of the language features, support for multi-method and/or
delegation, etc... Of course, the more you want, the more work is
needed, but starting with generic interfaces and no inheritance can
lead to something very simple, efficient and generic enough if you
focus only on containers.

Please explain how that would look like, specifically for, say, lists.

How would I call iList.Add(List,data);
in your proposal?

Thanks

jacob
 
N

Nick Keighley

OK, I get it. You hate the idea. Many things have already been done in
C++. OTOH there are many places where C++ cannot be used for a variety
of reasons. Some of these places have uses for containers and writing a
container from scratch is a non-trivial task.

By all means critique someone's code but the above is not that, it is
just a very negative criticism. If 'it has been done before elswhere'
were a reason for not doing something there is not much that most people
could do.

I'm not sure I agree his criticism is entirely negative. There are
some things that are just not worth doing. Writing a compiler in
COBOL.

On the other hand I'm not sure a container library in C is entirely
mad. Though Jacob's is a bit ambitious.

Ed, this has been endlessly debated in comp.lang.c already (and
glancing down-thread- looks about to be again!). Check the archive.
Jacob's gonna do it. Jacob is a confirmed C fan and a confirmed C++
non-fan (too big, too complicated). He believes by adding a few extra
features and libraries that C can be given a new lease of life.
 
E

Ed

Nick said:
I'm not sure I agree his criticism is entirely negative.

It wasn't AT ALL NEGATIVE.
There are
some things that are just not worth doing. Writing a compiler in
COBOL.

On the other hand I'm not sure a container library in C is entirely
mad.

And thousands have already done it. So this 10000th time, this one is
going to become a standard? What are the chances? I don't think you can
introduce a construct with "->VTable" in it and appeal to a major portion
of a C audience. There are many things like that in the document he
offered up above which indicates to me that he is quite disillusioned
about the whole concept of A.) What level of effort and knowledge
creating such a library entails, and B.) What level of evolved quality
such a library would have to attain before being worthy of presentation
to a standards organization, and C.) The "spirit of C" and how to market
to a larger segment of the C user base. To say "here is my ad hoc
container library" is quite different from saying "here is my proposal
for a container library to be in the next C standard".

Not that I'm knocking it. It's just fun to analyze projects and why they
go awry.
Though Jacob's is a bit ambitious.

Ed, this has been endlessly debated in comp.lang.c already

Oh. Did any conclusions come out of that back then?
(and
glancing down-thread- looks about to be again!). Check the archive.
Jacob's gonna do it. Jacob is a confirmed C fan and a confirmed C++
non-fan (too big, too complicated).

I was wondering if he knows the "other" language. Or any other other such
libraries for that matter since his approach seems to be that which has
been rejected eons ago (1993?) by container library developers.
He believes by adding a few extra
features and libraries that C can be given a new lease of life.

"few" being the keyword (NPI)? Knowing that it will take years to evolve
such a library, one must consider the relevence of C and the "need" for
such a libray for when it would actually become useful (years from now,
and if it's just one guy doing the development 5 years at least and many
complete overhauls of the architecture).

1.) I don't see the it happening without support from the language
proper. 2.) If the language proper is changed to accomodate elegant
implementation, then it's basically on the path of C++, so when does it
stop? When it becomes a C++ but only slightly different? Maybe THAT is
why there are so many libraries in C: the language doesn't have the
supporting mechanisms to allow an elegant implementation that anyone
would want to label as "The Standard C Container Library", so ad-hoc
implementation is actually PREFERRED. Not meaning "write your own",
(though you can), but rather obtain one that is already evolved.

So, just my .02, but I think container libraries for C are outside the
domain of the standard that is C and has been long ago decidedly
relegated to individual developers (companies). Finally, I DO think C
evolution has stopped long ago also and that it is in maintenance mode as
far as the standard goes. Anything else will be like a Borland Delphi was
to college-taught Pascal. Souping up C is like hotrodding an old car.
 
L

lawrence.jones

In comp.std.c Nick Keighley said:
I'm not sure I agree his criticism is entirely negative. There are
some things that are just not worth doing. Writing a compiler in
COBOL.

I actually tried that, back when I was young and foolish!
 
R

Ralph Malph

The function "int getline(char **,FILE *)" is declared but not defined,
And what erroneous behavior does that cause which may lead one
to classify this as a "bug"?
 
S

Sebastian

Pierre Asselin a crit :


Maybe you haven't noticed but ALL libraries (either in C or in C++)
are the same.

There are header-only libraries containing templates and inline
functions only. So, for example, if you have a header like
linkedlist.hpp and never use the class template's member function
mergesort(), the code just won't be generated. In terms of header
dependencies/compilation templates are kind of a horror but they also
have their advantages. The compiler only translating the functions
that are actually used is one of these advantages.

BTW: Have you heard about the abstraction penalty tests? The idea of
these tests is to check the quality of a C++ compiler / standard
library combination in terms of performance (speed, memory overhead,
etc). One typically expects a quality implementation of a "generic
container" to be about as efficient as its "handrolled" counterpart.
Resolving things at compile-time obviously helps here due to inlining
possibilities. Using function pointers may hurt performance. From what
I can tell, C++ combined with a quality implementation manages to get
both: low abstraction penalties and nice encapsulation. Do you expect
to be able to compete with this?

Cheers!
SG
 
I

ImpalerCore

It wasn't AT ALL NEGATIVE.

Any new container library is going to be compared against what is
already available. This kind of criticism is to be expected.
And thousands have already done it. So this 10000th time, this one is
going to become a standard? What are the chances?

In general I feel almost impossible. I think it's possible to
introduce a framework that gets collective support from some portion
of the C community (like GLib), but even hoping for that is quite a
long shot and would require an extraordinary amount of work. The
people who were actively working in container research passed C by a
long time ago, and without the prudent thinking of C++ proponents in
the early going before it was standardized, C++ may have missed the
STL and ended up with a similar situation to C; a multitude of vendor
driven container libraries.
I don't think you can
introduce a construct with "->VTable" in it and appeal to a major portion
of a C audience. There are many things like that in the document he
offered up above which indicates to me that he is quite disillusioned
about the whole concept of A.) What level of effort and knowledge
creating such a library entails, and B.) What level of evolved quality
such a library would have to attain before being worthy of presentation
to a standards organization, and C.) The "spirit of C" and how to market
to a larger segment of the C user base. To say "here is my ad hoc
container library" is quite different from saying "here is my proposal
for a container library to be in the next C standard".

Not that I'm knocking it. It's just fun to analyze projects and why they
go awry.

Can you explain what you mean by going awry in your context?
Oh. Did any conclusions come out of that back then?

No, but it's fun to rehash the argument with new attempts (I'm a
relative newcomer to clc). And it beats the usual spam that gets
posted. It got you to post didn't it ;-)
I was wondering if he knows the "other" language. Or any other other such
libraries for that matter since his approach seems to be that which has
been rejected eons ago (1993?) by container library developers.


"few" being the keyword (NPI)? Knowing that it will take years to evolve
such a library, one must consider the relevence of C and the "need" for
such a libray for when it would actually become useful (years from now,
and if it's just one guy doing the development 5 years at least and many
complete overhauls of the architecture).

I also have an interest in generic containers in C, but I don't have
nearly the amount of ambition as Navia has.
1.) I don't see the it happening without support from the language
proper.

While I believe that you will not achieve STL like capability with
template support, I do believe that there is potential; perhaps that's
me being young and foolish though ;-). The main drawback contrast
with C++ is that the C container interface will have to carry the type
around, whether manual casting and sizeof's, or wrapping the interface
with macros. It puts a larger burden on the programmer, but that's
what you get for using C.
2.) If the language proper is changed to accomodate elegant
implementation, then it's basically on the path of C++, so when does it
stop? When it becomes a C++ but only slightly different? Maybe THAT is
why there are so many libraries in C: the language doesn't have the
supporting mechanisms to allow an elegant implementation that anyone
would want to label as "The Standard C Container Library", so ad-hoc
implementation is actually PREFERRED. Not meaning "write your own",
(though you can), but rather obtain one that is already evolved.

I think that PREFERRED is too strong. I'm sure that most people here
think that the concept of a standardized C container library is "a
good thing". I also think that the container library should conform
to the language standard, and not the other way around. Getting
enough people to agreeing on what that library looks like though may
infer that no one could propose a library that could be universally
agreed to be considered the "C standard container library".
So, just my .02, but I think container libraries for C are outside the
domain of the standard that is C and has been long ago decidedly
relegated to individual developers (companies). Finally, I DO think C
evolution has stopped long ago also and that it is in maintenance mode as
far as the standard goes. Anything else will be like a Borland Delphi was
to college-taught Pascal. Souping up C is like hotrodding an old car.

I agree. The best that I think any aspiring C container library would
be is some kind of Boost like use. At the moment, I feel that someone
trying to get a C container library standardized borders on delusions
of grandeur. 30+ years of C and people much smarter than me and still
no standard C container library leaves me with no confidence that it
can be done. However, I enjoy arguing about it on clc.

Best regards,
John D.
 
J

jacob navia

Ed a écrit :
And thousands have already done it. So this 10000th time, this one is
going to become a standard? What are the chances? I don't think you can
introduce a construct with "->VTable" in it and appeal to a major portion
of a C audience.

Maybe that is right. That is why I do not use the ->VTable construct.
You CAN use it if you want container independence, but if you want
just to use a list you write

iList.Add(myList,data);

I would recommend you to READ the proposal before criticizing it. It
helps.

There are many things like that in the document he
offered up above which indicates to me that he is quite disillusioned
about the whole concept of A.) What level of effort and knowledge
creating such a library entails, and B.) What level of evolved quality
such a library would have to attain before being worthy of presentation
to a standards organization, and C.) The "spirit of C" and how to market
to a larger segment of the C user base. To say "here is my ad hoc
container library" is quite different from saying "here is my proposal
for a container library to be in the next C standard".

I am proposing a standard interface and offering a sample
implementation. The objective of the sample implementation is just
to show how it *could* be done.

I was wondering if he knows the "other" language. Or any other other such
libraries for that matter since his approach seems to be that which has
been rejected eons ago (1993?) by container library developers.

There hasn't been any proposal like this in the C standards discussion.
Since you haven't read the document I proposed you are just talking
nonsense.
"few" being the keyword (NPI)? Knowing that it will take years to evolve
such a library, one must consider the relevence of C and the "need" for
such a libray for when it would actually become useful (years from now,
and if it's just one guy doing the development 5 years at least and many
complete overhauls of the architecture).

This is just negative rubbish. "It will not work", "It is too much work"
"He will die before he finishes" "C will die before he finishes" and
other nonsense.
1.) I don't see the it happening without support from the language
proper.

You do not see it because there is no blinder person as the one that
doesn't want to see.

2.) If the language proper is changed to accomodate elegant
implementation, then it's basically on the path of C++, so when does it
stop?

This library proposes no language changes.


When it becomes a C++ but only slightly different? Maybe THAT is
why there are so many libraries in C: the language doesn't have the
supporting mechanisms to allow an elegant implementation that anyone
would want to label as "The Standard C Container Library", so ad-hoc
implementation is actually PREFERRED.

What is needed is a standard so that the code thatUSES this container
library is PORTABLE. The objective of a standard is portability. If we
agree to use this framework and to write our container libraries within
this framework code will be portable.

That is the objective here. Code reuse and portability.


Not meaning "write your own",
(though you can), but rather obtain one that is already evolved.

So, just my .02,

sorry I do not see even one cent in your contribution. Please read the
proposal before continuing.


but I think container libraries for C are outside the
domain of the standard that is C and has been long ago decidedly
relegated to individual developers (companies). Finally, I DO think C
evolution has stopped long ago also and that it is in maintenance mode as
far as the standard goes. Anything else will be like a Borland Delphi was
to college-taught Pascal. Souping up C is like hotrodding an old car.

What bothers me is not your opinion, you are entitled to it. What
bothers me is that you come to a C forum to tell everybody how bad
C is, without any desire to read the proposals, understand what is being
proposed, etc. You come here with your prejudices:

C is dead

C is in maintenance mode

C has no future

and you just talk nonsense around.
 
S

Squeamizh

It wasn't AT ALL NEGATIVE.



And thousands have already done it. So this 10000th time, this one is
going to become a standard? What are the chances? I don't think you can
introduce a construct with "->VTable" in it and appeal to a major portion
of a C audience. There are many things like that in the document he
offered up above which indicates to me that he is quite disillusioned
about the whole concept of A.) What level of effort and knowledge
creating such a library entails, and B.) What level of evolved quality
such a library would have to attain before being worthy of presentation
to a standards organization, and C.) The "spirit of C" and how to market
to a larger segment of the C user base. To say "here is my ad hoc
container library" is quite different from saying "here is my proposal
for a container library to be in the next C standard".

Not that I'm knocking it. It's just fun to analyze projects and why they
go awry.

Quit being such a pain in the ass.
 
L

ld

ld a crit :





Please tell me specific instances of "buggy"...
Thanks :)

in list.c:

// line 18
typedef struct _list_element {
struct _list_element *Next;
char Data[MINIMUM_ARRAY_INDEX];
} list_element;

// line 63
result = MALLOC(li,sizeof(*result)+li->ElementSize);

// line 73
memcpy(&result->Data,data,li->ElementSize);

// line 348
static void * GetElement(List *l,size_t position)
{
....
return rvp->Data; // UNDEFINED BEHAVIOR
}

// line 488
static bool Equal(List *l1,List *l2)
{
CompareFunction fn;
....
fn = l1->Compare;
fn(link1->Data,link2->Data,&ci) // UNDEFINED BEHAVIOR
}

idem in IndexOf, lcompar+sort, Apply, GetFirst, GetNext, GetPrevious,
GetCurrent, and so on...
idem for all your containers (I haven't checked all)...

My guess is that you write code only on Intel platform and don't know
what memory alignment constraints means (aka "bus error" on Unixes).
In particular, your container store object by "value" and


No, because you can just store a POINTER to your data, instead of the
data. Yes, I store the objects by value, but that "value" can be just a
pointer, and in that case you have a store by reference.

the problem is that you use void pointers everywhere, so from the
user's point of view, it will very be hard to make the difference
between pointer to pointer, pointer to value, pointer to "internal"
data structures (e.g. list_element), etc...
What is nice in this interface is that the decision of storing by value
or by reference can be done by the end user of the library and not by
the library writer.
It would be also nice to
split the file container.h into separate headers for each container
and to avoid the use of reserved identifier (_[AZ]).

That can be done but I think it uses up too much memory (neuron memory
in the user's brain). You would have to remember that

#include <list.h>
#include <arraylist.h>

or it was

#include <lists.h>
#include <arraylists.h>

???

Please let's simplify.
- "Sub-classing" section has nothing to do with the term subclassing
in the literature.

Sub-classing as is understood in event-oriented programming (Windows
system for instance) means to put yourself at a specific point in a
call-chain.

If function a calls function B that calls function C in a call chain,
you replace the function pointer in the vtable of B, and instead of
calling C directly you do something and THEN call C, or you call
C and THEN you do something, or you do not call C at all.

this is called "method swizzling" and it's dangerous when applied on
an entire "class".

http://zathras.de/angelweb/blog-method-swizzling-considered-harmful.htm
Can you elaborate?

As soon as you change something dynamically (possibly after instances
creation) in the behavior of a static type, you break the type system.
Precisely the ability of replacing those function pointers with your own
is one of the advantages of my approach.

do you have a useful application of what you propose?
Globals are thread safe if you understand that a shared ressource
needs semaphore protection before you change it.

Not only before you change it, but also *every time you read it*.
That's why it has a strong impact on how you access your vtable, and
therefore your interface. You can have a look to the history of errno
to see how threads introduced trouble to this global variable.
But this is so basic I
surely do not need to explain it to you.

This is far from being basic since it's part of one of the most active
research field in computer science (e.g. memory models, transactional
memory, etc...). But here again, I guess you have never used system
threads or only on Intel platforms with specific hardware support
(e.g. caches controllers support snooping and snarfing).
But maybe you mean something else? Please explain.
Done.


Why?

see above.
People that want to change a global resource can do it themselves.

Suppose I follow your advice. Then all changes (and each change) to the
tables provokes a copy.

not each changes, each time you want to create a "derived type"
That can be exactly what is needed in some
situation where you need to be able to go back and have the old
behavior, but could be just a waste if you do NOT want the old behavior
because you do not want to ever use it.

see above.
In the second case the wasted space is unavoidable if you have a
provided method.


Can you elaborate? I just do not understand what you mean here.

google for "method swizzling", "class posing", "meta-object protocol
or MOP", and related topics.
No. If you write:
        Myobject->VTable->Add(Object, data);
instead of
        iList.Add(Object,Data);

In the first case, the code REMAINS THE SAME if the object changes from
List to Array to whatever.

Not what so ever, your interfaces are not identical and the overuse of
void pointers make this kind of manipulation extremely error prone.
It is only in the second case that you need to change the code.
Using the FIRST syntax, even if it is more cumbersome, you have
container independence. Obviously the declaraion of "Object" must be
changed anyway.

That was my point, re-read my prose: "declaration of locals and
args" (just below).
No, see above.


It doesn't need improvement.

Ok. Go on, it's perfect.
Because I am not writing a full fledged framework for object oriented
programming in C but a container's library that should be extremely
small, stay within the language, and not invent a new way of doing OO
programming in C.

That was my proposal, see last line of my post. I don't talk to
rewrite OOC nor COS (from scratch, this would take you years).
YOU have done that. That is a DIFFERENT project.


Please explain how that would look like, specifically for, say, lists.

How would I call iList.Add(List,data);
in your proposal?

I would call it the same since this is a statically typed call
equivalent to iList_Add(List, data) (unless the vtable is read-write
which is not acceptable). I was talking about dynamic_cast, or
interface a-la-java or dictionary a-la-Haskell, which means how to
find a subset of the iList interface at runtime (after a static type
erasure) like comparable, serializable, iterable, etc... For example,
with an array of void pointers, you can do nothing safe, but with an
array of struct object* you can recover the original type of the
container (list) and all its implemented interfaces safely (or manage
properly the non-support for the interface you are looking for). This
will allow to write generic Apply for all containers which support the
interface iterable for example. Again all this in C requires only few
extra lines of code and some coding convention comparing to classical
ADT interfaces in headers.

Cheers,

Laurent.
 
B

Ben Bacarisse

Ralph Malph said:
And what erroneous behavior does that cause which may lead one
to classify this as a "bug"?

With the supplied makefile it prevents compilation by conflicting with
GNU getline. The makefile calls the compiler in a mode in which GNU's
getline is visible. This is fortunate since, otherwise, the arguments
in the call to getline would not match those required by either GNU
getline or the function with that name that Jacob has supplied. Jacob's
getline has a different type to GNU's getline but neither match the
prototype. Jacob's version is not used (as far as I can see) but the
call to getline still won't match any actual function available on my
system.
 
B

Ben Bacarisse

jacob navia said:
Ian Collins a écrit :
Yes, that has been corrected, see the changelog

Not as far as I can see, but the reasons are off-topic here. Mail me if
you'd like more details.
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,223
Latest member
Jurgen2087

Latest Threads

Top