Le 20/12/2013 15:55, Tim Rentsch a écrit :
jacob navia said:
[description of list structure definitions]
Feel free to comment on this.
Before offering comments I would like to ask a couple of
questions. (I ask because I expect what comments are offered
will likely depend on the answers.)
1. What are you hoping to accomplish by writing (meaning
both designing and implementing) such a package?
2. What are you hoping to accomplish by posting descriptions
(or partial descriptions) of said design and implementation
in the newsgroup here?
Please note that the questions are about what you hope to
accomplish, not why you want to accomplish it (or them) or
why accomplishing it/them might be desirable. What comments
I would offer depends on the goals, but not on what the
underlying motivations might be.
The answer to (1) and (2) is very simple:
I want to develop the C language and the discussion about it.
This is my stated goal since around 15 years.
Yes, C is an outdated, primitive language that should be forgotten
and replaced by C++. I have heard that many times and if you will
excuse me, I do not buy it.
I have proved that a containers library can be written completely
in C, and be as efficient and concise as the one in C++.
See my answer to Mr Garteth Owen (<
[email protected]>)
He said:
--------------------------------------------------start quote
How would you implement the following in CCL?
void complex_function(const std::list<std::list<double> >&);
void make_list_of_lists(size_t siz)
{
using std::list;
list<list<double> > list_of_lists;
for(size_t z=0;z<siz;++z){
list<double> tmp;
FillList(tmp,z);
list_of_lists.push_back(tmp);
}
complex_function(list_of_lists);
}
Don't forget to include cleanup, and some method of propagating memory
exhaustion errors back to the caller.
---------------------------------------------------end quote
I answered:
-------------------------------------------------start quote
Using a GC the code is:
void make_list_of_lists(size_t siz)
{
List *ListOfLists = iList.Create(sizeof(List *));
if (ListOfLists == NULL) {
goto NoMem;
}
for (size_t z = 0; z<siz; ++z) {
List *doubleList = iList.Create(sizeof(double));
if (doubleList == NULL) goto NoMem;
FillList(doubleList,z);
int r = iList.Add(ListOfLists,doubleList);
if (r == CONTAINER_ERROR_NOMEMORY) {
NoMem:
exit(1);
}
}
}
Using manual cleanup:
void make_list_of_lists(size_t siz)
{
List *ListOfLists = iList.Create(sizeof(List *));
if (ListOfLists == NULL) {
goto NoMem;
}
iList.SetDestructor(ListOfLists,
(DestructorFunction)iList.Finalize);
for (size_t z = 0; z<siz; ++z) {
List *doubleList = iList.Create(sizeof(double));
if (doubleList == NULL) goto NoMem;
FillList(doubleList,z);
int r = iList.Add(ListOfLists,doubleList);
if (r == CONTAINER_ERROR_NOMEMORY) {
NoMem:
exit(1);
}
}
complex_function(ListOfLists);
iList.Finalize(ListOfLists);
}
As you can see, C is slightly longer than C++ but there isn't a
factor of three involved, just a few lines.
-------------------------------------------------end quote
It is interesting that you ask me "What are you trying to accomplish"
when, in fact, it should be evident.
Again:
I am trying to develop the C language and the discussion about it.
I have proved with my package that C is just as capable as C++ of
having a containers library.
I spent around 5.000 dollars of my own pocket to go to Portland to
present my work to the C standards comitee, with the idiotic idea
that the committee would be interested in developing the C language.
I learned that the committee (that has many members that are also
in the C++ committee) thinks that any such package would be
a competition for the C++ STL and should be banned.
There were some people that argued otherwise however, people that
told in public that my proposal was the best proposal (for its
documentation and scope) that they had seen in years.
I was very affected by this defeat and haven't touched the package
for almost two years.
But being what I am, I started working in my compiler system again
and posting here again.