Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: The C Containers library |
| Date | 2015-11-02 22:33 +1300 |
| Message-ID | <d9ooukF6ovuU5@mid.individual.net> (permalink) |
| References | (2 earlier) <406c3221-7cfe-4e8f-8441-a97e0ce48122@googlegroups.com> <87d1vt7k2b.fsf@bsb.me.uk> <eb315076-70ea-4fa0-aead-0abcf9b0dd81@googlegroups.com> <87fv0p5lfg.fsf@bsb.me.uk> <aeab9efd-0f6b-4da3-90c3-42f5fd1863d9@googlegroups.com> |
Malcolm McLean wrote:
> On Sunday, November 1, 2015 at 11:50:35 PM UTC, Ben Bacarisse wrote:
>> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
>>
>> I can see how to simplify the language by removing the type-checking
>> (you use void * and sizes) but then it's not true that problems simply
>> don't arise. If you keep the idea of types (with all the safety that
>> brings with it) then there is complexity that C can't abstract over.
>>
> It's not all or nothing - "types" or "binary bits". You can allow
> very rich types, like C++.
Or C.
> But then that means that "memcpy(&dest, &src, sizeof(type)) is no
> longer adequate.
Which happens as soon as you have a struct with pointer members and you
want to maintain some degree of sanity regarding ownership of the
dynamic memory.
> So you need a "copy constructor". Which means that
> containers need some way of automatically linking to the copy
> constructor. Then you find that, for efficiency, you need a "move
> constructor". You also need a "default constructor" to create
> null objects, which gives rise to the concept of the "null object"
> as well as the "null pointer - all the methods have to react
> appropriately to being passed a null object. The complexities grow.
That's something I've very rarely seen in C++ or C. If a default
constructor isn't appropriate, block it.
> A C "vector", however, is simply
>
> struct C_vector
> {
> unsigned char *base;
> int N; // number of elements
> int size; // buffer size
> size_t elsize; // size of element
> }
>
> then you use memmove and memcpy to keep the contents in an array.
> There's no complexity of constructor calls.
For trivial data types, maybe. For most real world ones, things will
get more complicated.
--
Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 10:24 +0100
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-01 22:43 +1300
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 12:08 +0100
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-02 10:46 +1300
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 23:10 +0100
Re: The C Containers library gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 10:57 +0000
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 10:57 +0000
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 03:30 -0800
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 16:36 +0000
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 10:04 -0800
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-02 07:23 +1300
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 13:25 -0800
Re: The C Containers library supercat@casperkitty.com - 2015-11-01 15:44 -0800
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 23:50 +0000
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 01:19 -0800
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-02 22:33 +1300
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 02:04 -0800
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-01 12:04 -0800
Re: The C Containers library Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-01 15:41 -0500
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-01 13:26 -0800
Re: The C Containers library Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-01 16:50 -0500
csiph-web