468,242 Members | 1,635 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

what do c developers do without the stl?

I have recently gone back to doing some work in c, after years of c++, but I
find the lack of templates and in particular the container in the stl to be
a huge show stopper.
There are math libs, plotting libs, graphic libs etc but I what about some
usefull container lib. Any ideas anyone?
regards,
Conrad Weyns
Nov 14 '05 #1
32 1733
Conrad Weyns wrote:
I have recently gone back to doing some work in c, after years of
c++, but I find the lack of templates and in particular the
container in the stl to be a huge show stopper.
There are math libs, plotting libs, graphic libs etc but I what
about some useful container lib. Any ideas anyone?


Personally, I redo my strings like so:

http://bstring.sf.net/

and I do things like this:

http://www.pobox.com/~qed/ll.zip

to give me functionally very similar (I mean considering my typical
emphasis in data types) to STL. There are other libraries out there
like:

http://www.xref-tech.com/sglib/main.html

which covers even more.

---
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 14 '05 #2
Conrad Weyns wrote:
There are math libs, plotting libs, graphic libs etc but I what about
some usefull container lib. Any ideas anyone?


I use GLIB from Gtk+ (you don't need to be doing GUI programming to use
it -- it's perfectly separable from the rest of Gtk+):

http://www.gtk.org/

API Docs: http://developer.gnome.org/doc/API/2.0/glib/index.html

Of course those of us who program in Scheme and Lisp stand in wonder at
how everyone else gets by without a real macro system :)

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017

Nov 14 '05 #3

"Conrad Weyns" <we***@online.no> wrote in message
news:vo*******************@news4.e.nsc.no...
I have recently gone back to doing some work in c, after years of c++, but I find the lack of templates and in particular the container in the stl to be a huge show stopper.
There are math libs, plotting libs, graphic libs etc but I what about some
usefull container lib. Any ideas anyone?
regards,
Conrad Weyns


call me crazy, I made my own.

for fun and learning
Nov 14 '05 #4
Conrad Weyns wrote:
I have recently gone back to doing some work in C after years of C++
but I find the lack of templates
and in particular the container[s] in the stl to be a huge show stopper.
There are math libs, plotting libs, graphic libs etc.
but I what about some usefull container lib.
Any ideas anyone?


Yes.
C really needs a standard template library.
Why don't you propose one
and implement a reference library.
You will need preprocessor to convert templates into C code.

Take a look at the cncl/bin/genclass script which is part of
the ANSI C Numerical Class Library (CNCL)

http://www.netwood.net/~edwin/svmtl/
Nov 14 '05 #5

<we******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Conrad Weyns wrote:
I have recently gone back to doing some work in c, after years of
c++, but I find the lack of templates and in particular the
container in the stl to be a huge show stopper.
There are math libs, plotting libs, graphic libs etc but I what
about some useful container lib. Any ideas anyone?
Personally, I redo my strings like so:

http://bstring.sf.net/

and I do things like this:

http://www.pobox.com/~qed/ll.zip

Many thanks, Paul.
Conrad
to give me functionally very similar (I mean considering my typical
emphasis in data types) to STL. There are other libraries out there
like:

http://www.xref-tech.com/sglib/main.html

which covers even more.

---
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 14 '05 #6

"Jonathan Bartlett" <jo*****@eskimo.com> wrote in message
news:42********@news.tulsaconnect.com...
Conrad Weyns wrote:
There are math libs, plotting libs, graphic libs etc but I what about
some usefull container lib. Any ideas anyone?
I use GLIB from Gtk+ (you don't need to be doing GUI programming to use
it -- it's perfectly separable from the rest of Gtk+):

http://www.gtk.org/

API Docs: http://developer.gnome.org/doc/API/2.0/glib/index.html


Many thanks, this was most usefull.
Of course those of us who program in Scheme and Lisp stand in wonder at
how everyone else gets by without a real macro system :)
:-)
Regards,
Conrad Weyns.

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017

Nov 14 '05 #7
online wrote:
<we******@gmail.com> wrote in message
Conrad Weyns wrote:

I have recently gone back to doing some work in c, after years of
c++, but I find the lack of templates and in particular the
container in the stl to be a huge show stopper.
There are math libs, plotting libs, graphic libs etc but I what
about some useful container lib. Any ideas anyone?


Personally, I redo my strings like so:

http://bstring.sf.net/

and I do things like this:

http://www.pobox.com/~qed/ll.zip


Many thanks, Paul.


I advise extreme caution in using that package. The following is a
quote from Hsiehs own documentation:

"Bstrlib has been tested on the following compilers:

Microsoft Visual C++
Watcom C/C++ (32 bit flat)
Intel's C/C++ compiler (on Windows)
The GNU C/C++ compiler (on Windows/Linux on x86 and PPC64)
Turbo C"

Note that he does not specify the compiler versions, and that
functioning via a particular compiler is much different from
adhering to the ISO C standard.

He has also been known to advocate that ints are always 32 bits, or
that shifting signed quantities is harmless. Meanwhile the string
operations specified by the Standard are guaranteed portable and
available in all hosted systems.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #8
Hello everybody,

I am maintaining a simple generic library for C. It is freely
inspired by STL and it uses preprocessor to simulate templates.
The library is available at http://www.xref-tech.com/sglib/
I would like to compose a proposal to our national scientific
grant agency for some funds for this project and I need to
argue that this is a good idea and that (at least some)
community needs it. Looking at this thread, I think that
this is the best place to ask the following questions.

Do you have any ideas, why such library should exists? Are
there some living software projects written in C? Are there
some new projects which will be written in C? Would you use
such library, if available in a professional quality? Which
functionality would you expect from such library?

If you are working on a living C project and you think that
such library would be a good thing, please let me know. This
will help me a lot in composing the grant proposal.

Thanks in advance,

Marian Vittek

E. Robert Tisdale wrote:
C really needs a standard template library.
Why don't you propose one
and implement a reference library.
You will need preprocessor to convert templates into C code.

Take a look at the cncl/bin/genclass script which is part of
the ANSI C Numerical Class Library (CNCL)

http://www.netwood.net/~edwin/svmtl/


Nov 14 '05 #9
Marian wrote:
E. Robert Tisdale wrote:
C really needs a standard template library.
Why don't you propose one
and implement a reference library.
You will need preprocessor to convert templates into C code.

Take a look at the cncl/bin/genclass script which is part of
the ANSI C Numerical Class Library (CNCL)

http://www.netwood.net/~edwin/svmtl/


I am maintaining a simple generic library for C. It is freely
inspired by STL and it uses preprocessor to simulate templates.
The library is available at http://www.xref-tech.com/sglib/
I would like to compose a proposal to our national scientific
grant agency for some funds for this project and I need to
argue that this is a good idea and that (at least some)
community needs it. Looking at this thread, I think that
this is the best place to ask the following questions.

Do you have any ideas, why such library should exists? Are
there some living software projects written in C? Are there
some new projects which will be written in C? Would you use
such library, if available in a professional quality? Which
functionality would you expect from such library?

If you are working on a living C project and you think that
such library would be a good thing, please let me know. This
will help me a lot in composing the grant proposal.


I suspect you want to be taken seriously. You really should have
looked for a better injection site than as a reply to our resident
troll. Maybe that is why you top-posted? If not, bear in mind
that top-posting is considered rude and foolish here.

I suspect that template like things will hide too much to really
get accepted in C. Just look at how typdef is deregoted by many.

At any rate, you have two paths available: A standard macro
pre-processor such as M4, or the C preprocessor. With the C
preprocess you have access to the other C standard headers, with M4
you don't, as they need not exist as files. The C preprocess is
heavily limited as to abilities. M4 won't have access to such
things as INT_MAX.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #10
I am perfectly serious. What do you mean by top-posting?

The library uses C preprocessor. It is just a single header
file written in ANSI C defining all algorithms in form of macros.
It is perfectly operational. Originally, I have written in for
myself, then I have put it on the web. It is for free.

I am just asking people here if there is some "real-life" interest in
further works on it. What is wrong with it?

marian

Nov 14 '05 #11
Well, if you want C++, you know where to find it.

If you want a useful dynamic array library, just download FreeDOS Edlin
2.4 and marvel at a dynamic array of dynamic string library code.

Gregory Pietsch

Nov 14 '05 #12
Marian wrote:
I am maintaining a simple generic library for C.
It is freely inspired by STL
and it uses preprocessor to simulate templates.
The library is available at

http://www.xref-tech.com/sglib/

I would like to compose a proposal
to our national scientific grant agency
for some funds for this project
and I need to argue that this is a good idea
and that (at least some) community needs it.
Looking at this thread, I think that
this is the best place to ask the following questions.

Do you have any ideas, why such library should exists?
Are there some living software projects written in C?
Are there some new projects which will be written in C?
Would you use such library, if available in a professional quality?
Which functionality would you expect from such library?

If you are working on a living C project
and you think that such library would be a good thing,
please let me know.
This will help me a lot in composing the grant proposal.


I think that Conrad Weyns was looking for something
that looked like the Standard Template Library (STL)

http://www.sgi.com/tech/stl/
There are lots of problems with an implementation
as C preprocessor macros.
They are hard to read, understand and maintain.

Try using Google to search for answers to your questions above.
I'm sure that you can find ample justification for the STL in C.
Of course, you shouldn't expect it to be any easier
to get C programmers to use the STL than it was
to get C++ programmers to use the STL.
You might want to read something about the history of the STL.
It took a lot of people and a long time to develop the STL
and it took a long time to get it accepted as part of the C++ standard.
They are still trying to get C++ programmers to accept it.
Nov 14 '05 #13
E. Robert Tisdale wrote:
I think that Conrad Weyns was looking for something
that looked like the Standard Template Library (STL)

http://www.sgi.com/tech/stl/

I know.

There are lots of problems with an implementation
as C preprocessor macros.
They are hard to read, understand and maintain.


It does not mean they are so hard to use :) Also
the C preprocessor is stronger than people think.

I have nothing against glib from gtk, however it forces
you to represent, for example, a list of doubles as
a list of pointers to doubles and you need to do casts
from (void *) all the time. From my point of view, the
type checking is a good thing and consequently too many
casts is not a good practice.

A well written generic macro seems to be a better solution.
And of course it is better than writting the same code
again and again all the time.

Marian

Nov 14 '05 #14
In article <11**********************@l41g2000cwc.googlegroups .com>,
vi****@main.xref.sk says...
I am perfectly serious. What do you mean by top-posting?
It translates as "google is the bain of Usenet's existence".
Hint: Use the reply button at the TOP of the page when
using google, instead of the broken one at the bottom.
Also, add you text below, or interleaved with that you
are replying to, as I am doing here.
The library uses C preprocessor. It is just a single header
file written in ANSI C defining all algorithms in form of macros.
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++, and if you don't...
well, there is always C. I'm not sure why tax dollars should
go to reinventing the wheel here, but there is ample precedent
for the government doing that.
It is perfectly operational.
Really? Then why do you need grant money? It's done. :-)
Originally, I have written in for
myself, then I have put it on the web. It is for free.
Make it open source, and let the community keep it up. If its
useful, it will basically "maintain itself".
I am just asking people here if there is some "real-life" interest in
further works on it. What is wrong with it?


Put it on slashdot if you want to find out how it plays to a large
audience.

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #15
In article <11*********************@l41g2000cwc.googlegroups. com>,
vi****@main.xref.sk says...
Do you have any ideas, why such library should exists?
Not really. If I need the STL, I know where to find one that
has been widely used and tested.
Are there some living software projects written in C?
You must be joking.
Are there some new projects which will be written in C?
Several daily, I'm sure.
Would you use such library, if available in a professional quality?


Probably not, unless you guarantee it will work on about a dozen
different platforms and compilers. Even then, I don't think I
have a need for it. What I'd much rather see is a Grand Unified
Multithreading interface for C, that works regardless of platform.
Have one of those on the back burner?

That's going to be big. Probably could even get some grant money
for it.

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #16
In article <11**********************@g14g2000cwa.googlegroups .com>,
GK**@flash.net says...
Well, if you want C++, you know where to find it.
Wondered how long that would take.

If you want a useful dynamic array library, just download FreeDOS Edlin
2.4 and marvel at a dynamic array of dynamic string library code.
:-) Wonder how you knew about that?
Gregory Pietsch


Oh, that's how.

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #17
Marian wrote:

I am perfectly serious. What do you mean by top-posting?
.... snip ...


You should quote enough from whatever you are replying to to
establish at least context. Each article should stand on its own.
The links below (in my sig) will help. Top-posting means placing
your answer before the quoted material, it should follow it (or be
interspersed) with non-germane matter snipped out.

The google reply system is seriously broken. To have at least a
reasonable chance of generating a sane reply, see below:

"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Nov 14 '05 #18
On 27 Apr 2005 08:15:01 -0700,
Marian <vi****@main.xref.sk> wrote
in Msg. <11**********************@l41g2000cwc.googlegroups .com>

This.

Ugh--it hurts just doing it ONCE.

--Daniel
I am perfectly serious. What do you mean by top-posting?

Nov 14 '05 #19
Randy Howard wrote:
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++,
There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?
It is probably not as easy as this. C an C++ are two different
languages.

and if you don't...
well, there is always C. I'm not sure why tax dollars should
go to reinventing the wheel here, but there is ample precedent
for the government doing that.
It is perfectly operational.
Really? Then why do you need grant money? It's done. :-)


I have to pay invoices :)
Originally, I have written in for
myself, then I have put it on the web. It is for free.
Make it open source, and let the community keep it up. If its
useful, it will basically "maintain itself".


It's just a header file. It must be open source and it is.
Nothing is maintaining itself. This is just an illusion that
some serious project can evolve without expenses.

Put it on slashdot if you want to find out how it plays to a large
audience.


I am starting here :)

Marian Vittek

Nov 14 '05 #20

CBFalconer wrote:
Marian wrote:

I am perfectly serious. What do you mean by top-posting?


You should quote enough from whatever you are replying to to
establish at least context. Each article should stand on its own.
The links below (in my sig) will help. Top-posting means placing
your answer before the quoted material, it should follow it (or be
interspersed) with non-germane matter snipped out.

The google reply system is seriously broken. To have at least a
reasonable chance of generating a sane reply, see below:

"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


I am sorry for this. I have got it in between.

Marian

Nov 14 '05 #21
In article <11*********************@o13g2000cwo.googlegroups. com>,
vi****@main.xref.sk says...
Randy Howard wrote:
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++,
There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?


Very good question. I've not seen either of them answer it.
It is probably not as easy as this. C an C++ are two different
languages.
True, but the differences are easy enough to overcome, especially
if you really need STL and can't bear to live without it. Surely
moving most projects from C to C++ would be easier than implementing
your own homegrown "STLfoo" for C.
It is perfectly operational.


Really? Then why do you need grant money? It's done. :-)


I have to pay invoices :)


Then perhaps you shouldn't be giving it away. Just a hint.
It's just a header file. It must be open source and it is.


You can copyright the contents of header files and charge
for their use, provided you can find someone willing to
pay to do so.

If not, then it's probably not worth paying for, so why should you
get grant money for it?
Put it on slashdot if you want to find out how it plays to a large
audience.


I am starting here :)


Oh, I thought you were serious.

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #22

On Thu, 28 Apr 2005, CBFalconer wrote:

The google reply system is seriously broken. To have at least a
reasonable chance of generating a sane reply, see below:

"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


True. But I strongly encourage you, and every Google Groups Beta user,
to switch interfaces. If you can't use a real newsreader, at least
move to Canada --- groups.google.ca, that is! Their interface is still
relatively un-broken, though it may not last long.

And send e-mail to gr************@google.com (that's
groups-support\@google.com, for you Google Groups BETA users). I've
cc'ed this message to them, for example.

HTH,
-Arthur
Nov 14 '05 #23

Randy Howard wrote:
In article <11**********************@l41g2000cwc.googlegroups .com>,
vi****@main.xref.sk says...
I am perfectly serious. What do you mean by top-posting?


It translates as "google is the bain of Usenet's existence".
Hint: Use the reply button at the TOP of the page when
using google, instead of the broken one at the bottom.
Also, add you text below, or interleaved with that you
are replying to, as I am doing here.

This advice is inaccurate. What the user needs to do is click "show
options" at the top of the message (not the page) then select the Reply
shown in the expanded message header.

However, that doesn't have anything to do with top-posting, but rather
the all too prevalent Google "no quotes at all" problem.

Brian (sadly still using Google to post, but not read, news)

Nov 14 '05 #24
Randy Howard wrote:
vi****@main.xref.sk says...
Would you use such library, if available in a professional quality?

Probably not, unless you guarantee it will work on about a dozen
different platforms and compilers.
A dozen compilers is doable. After you get past 3 compilers, it
usually gets pretty easy from there unless you are doing hard core
numerics.

Multiple platforms is different. If you want to cover what ANSI C
supposedly says it covers -- I would say I have barely ever heard of a
completely cross-platform application. I guess "Hello World" would be
the only case that springs to mind. But obviously install base is far
easier. If you do Windows/DOS, *nix, and MacOSX (which really just
*nix now) then you are well above 99.99% install base of
PCs/workstations. As for other devices, VxWorks and QNX will cover
most of the rest.
[...] Even then, I don't think I have a need for it.
Interesting. Do you use any prewritten source at all?
[...] What I'd much
rather see is a Grand Unified Multithreading interface for C, that
works regardless of platform. Have one of those on the back burner?
First of all, there is basically no serious application written in C
that works regardless of platform.

Depending on what you want from multithreading -- it can be a
complicated low-level interface to OS/platform specific features that
are not universal. Certainly, pre-emption is a non-universal platform
feature.

However, if you poke your head out of the sand and look at the work
being done in other scripting languages (Python, LUA, Perl and ErLang
specifically) you will see that they are *all* moving towards
multitasking solutions. Its been their one collective big "missing
feature". I'm not an expert at ErLang, but the other guys have
primarily focused on co-routines as their avenue to multithreading.
Lua probably has the best implementation of coroutines (although I
don't know about the details of ErLang.)

C's closest approximation to coroutine functionality is the
setjmp/longjmp, but I have looked into this, and its simply not
possible to duplicate the expected full functionality of "one-shot
continuation" style coroutines with it.

Running off to inline assembly, personally, I have implemented basic
coroutine functionality -- but the platform details are pretty
daunting. Even for *one* compiler, I have to supply multiple different
interfaces depending on which "ABI/calling convention" is being used.

Coroutines are a particularly good sweet spot, because it dramatically
increases programming capabilities without introducing, mutexes,
semaphores and race conditions. The implementation details also are
just generalizations of setjmp/longjmp with some call stack
manipulation capabilities. Coroutines can also be fairly fast, while
sync primitive multitasking objects can be very slow.
That's going to be big.
Well I don't know what you mean by this -- its not likely to ever come.
There are relatively few who understand the problem well enough to
even attempt it, and the ANSI C standard committee is not of any help.

The best chance would be to get the VxWorks or OSE guys to open source
their solutions, but they currently still make money off them, so I
don't know what you are expecting from them. By the time they might
consider open sourcing their solutions, the mindshare for C will have
eroded to the point where nobody cares anymore.
Probably could even get some grant money for it.


Yeah, the problem is, how do you get someone interested in giving you
grant money for such a thing? The effort required is fairly high, and
there will be no returns unless you sell the solution (which means not
making it an open standard).

---
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 14 '05 #25
Marian wrote:
Randy Howard wrote:
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++,


There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?
It is probably not as easy as this. C an C++ are two different
languages.


Yes, but paradoxically, this is the wrong newsgroup to discuss
something like a "standard generic library for C". There simply is no
audience for your ideas here. People may come here periodically with
such questions, but the loiterers here are more interested in the
standard of C than the practice of C. You'll notice you got a lot of
arrows slung at you, but not a lot of useful feedback.

There is a sentiment amonst some programmers that the only real value
of C++ is, in fact, STL. But as you correctly point out, C++ also
introduces many semantic language differences from C that may prevent
it from being adopted (not the least of which being that the C++
standard is something like 10 times larger) by programmers for various
reasons.

So the obvious conclusion is that if a good enough library of generics
(whether via macros, or whatever mechanism) were made available that,
there would be amongst those programmers I just referred to who would
probably be very interested in them. Then of course there are people
like me, who just sees the value of generics in general.

Ok, but that isn't exactly what you've provided. Instead, you've taken
a position that you will never dynamically allocate any memory or
create/declare your own fresh data structures. And what you are really
supplying is a set of algorithms which can be applied to data
structures that are user generated. That's fine, and an interesting
take on the problem, but then what you are doing is not exactly
comparable to what STL does.

For example, the primary value of STL that *I* personally saw, is the
inclusion of the vector<> template. A vector is like a dynamically
sized array -- it can be indexed directly, trivially iterated, sorted,
rotated, etc. Since you restrict yourself from use of malloc(), your
library doesn't implement any container abtraction for things such as
vectors or deques, etc -- you require an array based implementation by
the user, if you want to sort it, for example.

So in the end you will find yourself restricted, and certainly not able
to duplicate the entire functionality of STL. Your hash table, for
example, implements only the chaining-style hash tables, which are
generally somewhat slower than the open-address style.

I would also posit, that one of the main problems in C programming, is
that memory/buffer management is a common place for errors, many of
which have become quite famous bugs.

So I guess I would wonder if you would be willing to consider,
possibly, adding perhaps a "level 2 API" for building real ADT which
include their own memory management? That, I think, is where the real
holy grail for this kind of mechanism for C is.

But in generally, I highly endorse your mechanism for implementation.
Where C is very weak in many ways, one of its bizarre strengths is the
source-level macro concatenation feature. And its an interestingly
natural way of trying to implement generic programming in C.

---
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 14 '05 #26

"Marian" <vi****@main.xref.sk> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Randy Howard wrote:
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++,
There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?
It is probably not as easy as this. C an C++ are two different
languages.


I was having to do some work on a many years old c project. I was not going
back to using c by choice.
It would certainly be feasable to move it over to c++ but with any sizeable
project, this is never a cheap undertaking.
Years ago, when using only c, I'd simply get on with it and write whatever
it is that I needed to get the job done.
I was surprised now to find myself not quite willing to consider that!
So, after wasting at least half a day in a total void, I ended up writing a
few pages of uggly fixes that I hope no one else will ever get to review...

I certainly agree with Randy Howard:
Surely moving most projects from C to C++ would be easier than implementing
your own homegrown "STLfoo" for C.
Absolutely!
Were I to envisage a future using c, I'd certainly support your efforts to
make a good c stl alternative.
I'd have no problem paying for a license. Good, bug-free, third party
libraries are worth their weight in gold.
In my working world, I am seeing many years investment in c++ comming to an
end, in favour of .net and c#.
Cheers,
Conrad Weyns.

and if you don't...
well, there is always C. I'm not sure why tax dollars should
go to reinventing the wheel here, but there is ample precedent
for the government doing that.
> It is perfectly operational.


Really? Then why do you need grant money? It's done. :-)


I have to pay invoices :)
> Originally, I have written in for
> myself, then I have put it on the web. It is for free.


Make it open source, and let the community keep it up. If its
useful, it will basically "maintain itself".


It's just a header file. It must be open source and it is.
Nothing is maintaining itself. This is just an illusion that
some serious project can evolve without expenses.

Put it on slashdot if you want to find out how it plays to a large
audience.


I am starting here :)

Marian Vittek

Nov 14 '05 #27

"Marian" <vi****@main.xref.sk> wrote
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++,


There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?
It is probably not as easy as this. C an C++ are two different
languages.

When the stl came out I seriously considered switching to C++ for most of my
development.
However I decided against it. One reason was that the syntax is horrible.
The more important reason is that interfaces become complex.

For instance if you want to calculate a standard deviation in C you will
write something like

double stdev(const double *x, int N)

in stl the first reaction may be to pass in a vector of doubles.

double stddev( vector<double> x)

However to really get into the spirit of stl, the algorithm should work on a
controlled sequence of any numeric type. So you end up with something like

template <numeric>
numeric stdev( numeric::iterator start, numeric::iterator end)

This is a nice idea, but too hard to use. I'm not sure I've even got the
syntax right.

However it is very difficult to provide useful generic macros / functions in
C. It is easy enough to write an expandable vector, for instance, but if
most objects are small then the generic call to memcpy() is prohibitive.
Also, you must handle out-of-memory somehow, and C has no exception
mechanism. By the time you've finished you might as well just call
realloc(), with its annoying requirement for a temporary to handle failure
properly.
Nov 14 '05 #28
Malcolm wrote:
"Marian" <vi****@main.xref.sk> wrote
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++,
There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?
It is probably not as easy as this. C an C++ are two different
languages.


When the stl came out I seriously considered switching to C++ for most of my
development.
However I decided against it. One reason was that the syntax is horrible.
The more important reason is that interfaces become complex.

For instance if you want to calculate a standard deviation in C you will
write something like

double stdev(const double *x, int N)

in stl the first reaction may be to pass in a vector of doubles.

double stddev( vector<double> x)

However to really get into the spirit of stl, the algorithm should work on a
controlled sequence of any numeric type. So you end up with something like

template <numeric>
numeric stdev( numeric::iterator start, numeric::iterator end)

This is a nice idea, but too hard to use. I'm not sure I've even got the
syntax right.

However it is very difficult to provide useful generic macros / functions in
C. It is easy enough to write an expandable vector, for instance, but if
most objects are small then the generic call to memcpy() is prohibitive.
Also, you must handle out-of-memory somehow, and C has no exception
mechanism.


Use longjmp macros and wrap your malloc().

http://ldeniau.home.cern.ch/ldeniau/...exception.html

I have a different way of doing the cleanup handlers for freeing malloced
memory during an exception.
By the time you've finished you might as well just call
realloc(), with its annoying requirement for a temporary to handle failure
properly.

Nov 14 '05 #29
Malcolm wrote:
"Marian" <vi****@main.xref.sk> wrote
Interesting. The problem is, if you use C instead of C++, the
reason is often for something lighter weight than C++, so
if you need STL stuff, people would use C++,
There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?
It is probably not as easy as this. C an C++ are two different
languages.


When the stl came out I seriously considered switching to C++ for most of my
development.
However I decided against it. One reason was that the syntax is horrible.
The more important reason is that interfaces become complex.

For instance if you want to calculate a standard deviation in C you will
write something like

double stdev(const double *x, int N)

in stl the first reaction may be to pass in a vector of doubles.

double stddev( vector<double> x)

However to really get into the spirit of stl, the algorithm should work on a
controlled sequence of any numeric type. So you end up with something like

template <numeric>
numeric stdev( numeric::iterator start, numeric::iterator end)

This is a nice idea, but too hard to use. I'm not sure I've even got the
syntax right.

However it is very difficult to provide useful generic macros / functions in
C. It is easy enough to write an expandable vector, for instance, but if
most objects are small then the generic call to memcpy() is prohibitive.
Also, you must handle out-of-memory somehow, and C has no exception
mechanism.


Use longjmp macros and wrap your malloc().

http://ldeniau.home.cern.ch/ldeniau/...exception.html

I have a different way of doing the cleanup handlers for freeing malloced
memory during an exception.

Some real C code that does exception handling and cleanups is in gnu gdb.
By the time you've finished you might as well just call
realloc(), with its annoying requirement for a temporary to handle failure
properly.

Nov 14 '05 #30

Randy Howard wrote:
In article <11**********************@g14g2000cwa.googlegroups .com>,
GK**@flash.net says...
Well, if you want C++, you know where to find it.


Wondered how long that would take.

If you want a useful dynamic array library, just download FreeDOS Edlin 2.4 and marvel at a dynamic array of dynamic string library code.


:-) Wonder how you knew about that?
Gregory Pietsch


Oh, that's how.


So, I prosthelytize a little. Still, it's best to stick with something
that works. Why reinvent the wheel? ;-)

Gregory Pietsch
Gregory Pietsch

Nov 14 '05 #31
Do you have considered using libapr?

Regards
Friedrich
--
Please remove just-for-news- to reply via e-mail.
Nov 14 '05 #32
Marian Vittek wrote:
Conrad Weyns wrote:
Absolutely!
Were I to envisage a future using c, I'd certainly support your
efforts to make a good c stl alternative.
I'd have no problem paying for a license. Good, bug-free, third party
libraries are worth their weight in gold.
In my working world, I am seeing many years investment in c++ comming
to an end, in favour of .net and c#.
This was in some sens the main question I asked here. Is it
useful to invest time and money into such project? Until now,
I have worked on the library just for myself, implementing only
things I needed. If it should be a general purpose library,
it should cover much more. I hoped that there are still a lot of C
programmers. I hoped that they are using C (as me, I do) because they
consider it as the best solution.


FWIW: For many things, C IMO still is the best solution. In some
areas, it is the only solution (see embedded systems; writing
compilers for more complex languages than C89 just will not
pay. However, the C code for the embedded device may well be
partially created by other software _not_ written in C...)
Some established STL-like library for C might ease the
decision for C in some but certainly not all cases.
I certainly followed the discussion with some interest and
had a quick look at the SGLIB documentation.

People investing money only in NEW technologies may not be
favorable to any evolution in C area, certainly.


People investing money in new technologies only because they
are new technologies, are almost certainly wasting their money.
However, if there is a better technology for something and the
ROI (as much as I hate thinking in these terms) cries "yesss",
then it is no mean act of treason to turn your back on an old
solution. In fact, a clean cut from time to time may be the
only way to keep something alive and not only in some state
of suspended animation respawning for a couple of moments
every now and then.
Apart from that: C is my favourite programming language :-)
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #33

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

354 posts views Thread by Montrose... | last post: by
8 posts views Thread by Hermawih | last post: by
46 posts views Thread by Keith K | last post: by
132 posts views Thread by Kevin | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.