Boost process and C

C

CBFalconer

Ed said:
That all depends on the license under which the source code was
released. Linking a bunch of C libraries under various licenses can
involve non-trivial amounts of legal hassle to ensure compliance.

If you publish your source under GPL, there is very little chance
of conflicts. In the case of things I have originated, all you
have to do is contact me to negotiate other licenses. I can be
fairly reasonable on months with a 'R' in them.
Also, there's something to be said for having features built into the
standard library. Besides making things easier from a legal point of
view, it means you can spend that much less time evaluating multiple
solutions, since most of the time, you'll just use the implementation
already available in the standard library.

I know it's unpopular around these parts to utter such heresy, but I,
for one, would love it if the standard C library included support for
smarter strings, hash tables, and linked lists.

No, there is nothing wrong with expanding the standard library.
Nothing forces anyone to use such components anyhow. There is
provision in the standard for "future library expansion". This is
a far cry from bastardizing the language with overloaded operators
and peculiar non-standard syntax, as recommended by some of the
unwashed.
Then again, I'm certainly NOT advocating these things should be added
to the standard C library. I recognize C for what it is, and use it
where it's appropriate. There are other languages that offer those
features. But that doesn't stop me from wanting those features in C.

Go ahead and advocate. I would certainly like to see at least
strlcpy/cat in the next standard, with gets removed, and possibly
my own hashlib and ggets added. What all of those things are is
completely described in terms of the existing C standards, so the
decisions can be fairly black and white.

--
"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
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
F

Flash Gordon

Flash said:
Flash Gordon wrote:
(e-mail address removed) wrote:
Ben C wrote:
CBFalconer wrote:
(e-mail address removed) wrote:
CBFalconer wrote:
... snip ...
The last time I took an (admittedly cursory) look at Bstrlib, I
found it cursed with non-portabilities
You perhaps would like to name one?
I took another 2 minute look, and was immediately struck by the use
of int for sizes, rather than size_t. This limits reliably
available string length to 32767.
[snip]

[...] I did find an explanation and
justification for this. Conceded, such a size is probably adequate
for most usage, but the restriction is not present in standard C
strings.
Your going to need to conceed on more grounds than that. There is a
reason many UNIX systems tried to add a ssize_t type, and why TR 24731
has added rsize_t to their extension. (As a side note, I strongly
suspect the Microsoft, in fact, added this whole rsize_t thing to TR
24731 when they realized that Bstrlib, or things like it, actually has
far better real world safety because its use of ints for string
lengths.) Using a long would be incorrect since there are some systems
where a long value can exceed a size_t value (and thus lead to falsely
sized mallocs.) There is also the matter of trying to codify
read-only and constant strings and detecting errors efficiently
(negative lengths fit the bill.) Using ints is the best choice
because at worst its giving up things (super-long strings) that nobody
cares about,
I think it's fair to expect the possibility of super-long strings in a
general-purpose string library.
Ok, so you can name a single application of such a thing right?
Handling an RTF document that you will be writing to a variable length
record in a database. Yes, I do have good reason for doing this. No, I
can't stream the document in to the database so I do have to have it all
in memory. Yes, RTF documents are encoded as text. Yes, they can be
extremely large, especially if they have graphics embedded in them
encoded as text.
So now name the platform where its *possible* to deal with this, but
where Bstrlib fails to be able to deal with them due to its design
choices.
If the DOS port hadn't been dropped then depending on the compiler we
might have hit this. A significant portion of the SW I'm thinking of
originated on DOS, so it could have hit it.

Oh ... I think of DOS as exactly the case where this *can't* happen.
Single objects in 16bit DOS have a size limit of 64K (size_t is just
unsigned which is 16 bits), so these huge RTF files you are talking
about *have* to be streamed, or split over multiple allocations
anyways.

Strangely enough there have been ways of having objects larger than 64K
in DOS. At least, given a 386 and some extensions.
And how is this connected with Bstrlib? The library comes with a test
that, if you run in a 16 bit environment, will exercise length
overflowing. So you have some reasonable assurance that Bstrlib does
not make obvious mistakes with size computations.

You are assuming I won't want an object larger than can be represented
in an int. That is an artificial limitation.
[...] So I'll stick to not artificially limiting sizes.

And how do you deal with the fact that the language limits your sizes
anyways?

You are artificially reducing the limit below what the language allows
for. The language is not artificially reducing it below what the
language allows.
[...] If the administrator of a
server the SW is installed on wants then s/he can use system specific
means to limit the size of a process.

What? You think the adminstrator is in charge of how the compiler
works?

No, but the SW I'm dealing with is run on systems where the
administrator can limit process size, maximum CPU usage and lots of
other good stuff. Or the administrator can leave it unlimited (i.e.
limited by available resources). You really should try an OS that gives
real power and flexibility one day.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
 
C

CBFalconer

Chris said:
.... snip ...

Indeed. Suppose the String data structure is much like Paul Hsieh's
favorite, but perhaps with a few more bells and whistles (I have not
looked at his implementation):

Neither have I, beyond a cursory glance. However I did see that
the fundamental object involved is a struct, which contains a
length, a capacity, and a pointer to actual string data as an array
of char. This is an organization that has been in use for many
years in GNU Pascal. There are still awkwardnesses in its use,
such as the equivalent of a union of two strings, and how to handle
the capacity value. GPC does this by making such a union an actual
structure, with separate fields. But, by and large, it is a
familiar organization.

Any of these so-called advanced organizations have to give up
something, be it code compactness, efficiency, other limitations.
There are very few limitations to the null terminated string, which
is why it has endured. There are, however, many traps for the
unwary. This is the hallmark of virtually all C code.

You pays your money and you takes your choice.

--
"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
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
J

Joe Wright

Excuse me but what does it mean

Sep-25-1981 + Dec-22-2000

Just because the sum of two dates is not a date doesn't mean that
it doesn't mean anything.
You obviously meant:

mid_date = (end_date - start_date)/2

No I didn't. That is something completely different.
The *subtraction* of two dates yields a time interval

True, and (end_date - start_date) / 2 would give me half the interval
between the dates, but that is not what I wanted. I wanted the
average of the dates, which is a date.

(Sep-25-1981 + Dec-22-2000) / 2 would be the date mid-way between
Sep-25-1981 and Dec-22-2000, just as (45 + 78) / 2 is the integer
mid-way between 45 and 78.

-- Richard[/QUOTE]

Adding date values is nonsense. Subtracting one date from another to
yield integer days between two dates is very handy. Adding (or
subtracting) integer days to (or from) a date yielding a date is handy
too. Look at this ..

set century on // prints 1981 instead of 81
dbeg = ctod("09/25/1981") // convert character string to date type
dend = ctod("12/22/2000")
diff = dend - dbeg // 7028 days between two dates
? dbeg, dend, diff
dmid = dbeg + diff / 2 // begin date + 3514 days, yielding date type
? dmid // 05/10/1991

... in xBase, the language of dBASE, FoxPro, Clipper and xHarbour. While
C is my favorite language, my employer pays for xBase. I have a hobby
project to translate some of the more useful xBase stuff into C.

Note that ? is a print command in xBase. It prints a leading newline and
then the values of its arguments, separated by a space character.
 
R

REH

Ben C said:
Yes I know. But you do get constructors, destructors and references, so
you can fit explicit memory management "under the hood" of operator
overloading.

I can understood people's dislike of references (though I don't agree with
the reasons), but what is wrong with constructors and destructors?
Show me the string example, and hopefully either you will get my point
or I will get yours :)

I'd rather understand what you think is wrong this constructors. My
previous example can be written with constructors and will generate code
that is as efficient, if not more so, than without.

REH
 
W

websnarf

Flash said:
Flash said:
(e-mail address removed) wrote:
Flash Gordon wrote:
(e-mail address removed) wrote:
Ben C wrote:
CBFalconer wrote:
(e-mail address removed) wrote:
CBFalconer wrote:
... snip ...
The last time I took an (admittedly cursory) look at Bstrlib, I
found it cursed with non-portabilities
You perhaps would like to name one?
I took another 2 minute look, and was immediately struck by the use
of int for sizes, rather than size_t. This limits reliably
available string length to 32767.
[snip]

[...] I did find an explanation and
justification for this. Conceded, such a size is probably adequate
for most usage, but the restriction is not present in standard C
strings.
Your going to need to conceed on more grounds than that. There is a
reason many UNIX systems tried to add a ssize_t type, and why TR 24731
has added rsize_t to their extension. (As a side note, I strongly
suspect the Microsoft, in fact, added this whole rsize_t thing to TR
24731 when they realized that Bstrlib, or things like it, actually has
far better real world safety because its use of ints for string
lengths.) Using a long would be incorrect since there are some systems
where a long value can exceed a size_t value (and thus lead to falsely
sized mallocs.) There is also the matter of trying to codify
read-only and constant strings and detecting errors efficiently
(negative lengths fit the bill.) Using ints is the best choice
because at worst its giving up things (super-long strings) that nobody
cares about,
I think it's fair to expect the possibility of super-long strings in a
general-purpose string library.
Ok, so you can name a single application of such a thing right?
Handling an RTF document that you will be writing to a variable length
record in a database. Yes, I do have good reason for doing this. No, I
can't stream the document in to the database so I do have to have it all
in memory. Yes, RTF documents are encoded as text. Yes, they can be
extremely large, especially if they have graphics embedded in them
encoded as text.
So now name the platform where its *possible* to deal with this, but
where Bstrlib fails to be able to deal with them due to its design
choices.
If the DOS port hadn't been dropped then depending on the compiler we
might have hit this. A significant portion of the SW I'm thinking of
originated on DOS, so it could have hit it.

Oh ... I think of DOS as exactly the case where this *can't* happen.
Single objects in 16bit DOS have a size limit of 64K (size_t is just
unsigned which is 16 bits), so these huge RTF files you are talking
about *have* to be streamed, or split over multiple allocations
anyways.

Strangely enough there have been ways of having objects larger than 64K
in DOS. At least, given a 386 and some extensions.

For actual storage, you need go no further than a 8086, which could be
equipped with up to 640K of memory without issue. But of course,
that's not what's at issue here. Its a question of what size_t is on
those platforms. In all the 16 bit mode compilers I am aware of,
size_t (and int) is a 16 bit unsigned integer, which by the C standard,
says a single object cannot be more than 64K. This is a real issue
when you realize that if you perform a strcat on two strings each
greater than 32K, you get an undefined result, (because the C
specification is just a worthless in this respect).

If you want to use the 32 bit instruction x86 sets and a DOS extender,
you can use one of the 32 bit compilers, but here size_t is a 32 bit
unsigned integer (as is int.)

Perhaps you might want to refrain from chiming in about things you know
very little about; I mean seriously, are *YOU* trying to tell *ME* how
DOS works? Are you kidding me?
You are assuming I won't want an object larger than can be represented
in an int. That is an artificial limitation.

size_t is also a similar artificial limitation. The fact that arrays
can only take certain kinds of scalars as index parameters is also an
artificial limitation. But it turns out that basically every language
and every array-like or string-like (with the notable exceptions of Lua
and Python) has a similar kind of limitation.
[...] So I'll stick to not artificially limiting sizes.

And how do you deal with the fact that the language limits your sizes
anyways?

You are artificially reducing the limit below what the language allows
for. The language is not artificially reducing it below what the
language allows.

One of these statements is circular reasoning. See if you can figure
out which one it is.
 
B

Ben C

Ahh ok, you mean then

mid_date = startdate + (end_date-start_date)/2

Your attitude is baffling. You deny that adding dates makes sense,
and when I post an example where adding dates makes perfect sense, you
respond by asserting that I mean some other expression that achieves
that same effect. The mere fact that you were able to post another
expression with the same meaning refutes your original claim.[/QUOTE]

Mr Navia's attitude makes sense if you think of dates in "homogenous
coordinates".

It's common in 3D graphics to use 4-vectors to represent positions and
directions. A position has a 1 in its last element, and a direction has a
0.

I say directions, the vectors are not necessarily normalized, so they
are "directions with magnitude".

Positions implicitly mean "the place you get to if you start at the
origin and add the 3D part of the vector".

Directions-with-magnitude are not implicitly based at the origin. You
can add a d-with-m to a position to get to a new position.

[a0, a1, a2, 1] + [m0, m1, m2, 0] = [b0, b1, b2, 1]

If we do this as a 4D vector add, the result ends up correctly with a 1
in the 4th element-- it's a position.

Other implementation conveniences arise from this approach-- you can use
the last column of a 4D matrix to represent a translation. Applying the
matrix to a vector will rotate and then translate positions, but will
just rotate and not translate d-with-ms, because the 0 in the 4th
element will select out the last column in the matrix multiply.

Using this system, you should be able to do everything with straight 4D
matrix arithmetic, and if you ever end up with a 2 or a -1, or anything
that isn't 0 or 1 in the 4th element of a vector, you've done something
wrong.

Adding two positions, for example, gives you a 2 in that 4th element.
And, thinking of it geometrically, it doesn't make a lot of sense
because positions are implicitly "translations from the origin", so you
can't translate one position from another position.

Well, we can represent time in a 1D space and use 2D "homogenous
coordinates":

[100, 0] means "100 seconds forwards"
[-100, 0] means "100 seconds ago"
[100, 1] means "100 seconds since 1970-01-01T00:00"

In exactly the same way we distinguish between a length of time, and a
length of time that implicitly starts at the origin.

start_date + (end_date - start_date) / 2

doesn't generate any invalid last-elements in any intermediate results,
but

(start_date + end_date) / 2

does.

In Python's datetime module, subtracting two dates returns a "timedelta"
object, which can be added to a date. But two dates cannot be added.

This seems a sensible way to do it, and if you wanted to do it in C++, I
think you'd overload global operators, not member function operators:

Timedelta& operator-(const Date& a, const Date& b);
Date& operator+(const Date& a, const Timedelta& delta);
Timedelta& operator+(const Timedelta& a, const Timedelta& b);

etc. You could make a perfectly usable system this way, and I'd say that
using operators for dates is no more or less sane or insane than using
them for matrices and vectors.
 
B

Ben C

I can understood people's dislike of references (though I don't agree with
the reasons), but what is wrong with constructors and destructors?

Nothing, I like constructors and destructors.
 
R

Richard Bos

jacob navia said:
Besides, I think that using the addition operator to "add" strings is an
ABOMINATION because:

a+b != b+a
"Hello" + "World" != "World" + "Hello"

It just makes NO SENSE.

Quaternions must have come as a shock to you. Or does a*b != b*a somehow
make more sense to you than a+b != b+a?

Richard
 
R

Richard Bos

jacob navia said:
2) Operator overloading does NOT need any constructors, nor destructors
nor the GC if we use small objects:

int128 a,b,c,d;

a = (b+c)/(b-d);

You keep repeating this as one of the prime examples (in fact, the only
consistent example) of why overloading is so useful in your suite. Don't
you realise that C99 allows any implementation to define any size
integers without requiring overloading at all?

Richard
 
R

Richard Bos

jacob navia said:
Richard Bos a écrit :
[snip]
Three restrictions. And bright red uniforms. But those are not
references as it is generally understood. They're also mostly useless. I
cannot imagine wanting such a type when I already have normal pointers.
OTOH, they're also - being toothless - not harmful, the way a real
reference is.

For enlightenment on what is generally meant by "reference" in
programming, see the C++ Standard.

I do not really care, I am not trying to copy C++. The only advantage of
references is that they are never NULL in my implementation, and they
are (maybe) not as powerful as the C++ ones.

Then, as I said, they're neither useful nor references.
What is wrong with length prefixed strings Richard?

That's been discussed here so often that I really can't be arsed to
repeat the whole argument for the N+1th time.
Can you put forward your *arguments* instead of just sending polemic to
the discussion?

WHY are length prefixed strings wrong?

I am waiting for an argument Richard.

Don't cite other people's names like that jacob navia.

It does not make your posts any easier to read nor any more to the point
jacob navia.

Frankly, it makes you sound like a bit of a twerp jacob navia.

Richard
 
R

Richard Bos

Ian Collins said:
That's why we have const. If a function isn't going to change the value
passed in, it should reference (or pointer) to a const object. If the
parameter isn't const, assume the worst. No difference between pointers
and references in this case.

But you still can't tell from any particular _call_ to a function
whether that function is likely to change its arguments, or is
guaranteed not to. As long as you have references (real ones, not
navia-references), you cannot trust a single function call - you have to
look up all prototypes, even if you're only trying to understand someone
else's code.

Richard
 
R

Richard Bos

Robert Latest said:
If you don't like the features of C, you can either:

[ suggestions (1) through (4) snipped ]

(5) Write a compiler that supports the needed features,
preferably for a popular platform with a wide user
base such as Windows, and make it available for free.

If people like the language extensions, they will become popular
quickly and make it into other implementations as well, thus
creating what is known as a "de facto standard". No need to wait
for an ISO committee.

Perfectly good idea, _but_ if you do so, do not post samples of your
extended-not-quite-C here as if it were normal C, or a good solution to
a general problem.

Richard
 
R

Robert Latest

I think the point is that there are *many* such application. In fact I
would be suspicious of anyone who claimed to be an experienced
programmer who hasn't *written* one of these.

....and I would be suspcious of anyone who claimed to be an
experienced programmer who can't write the necessary routines
from scratch in less time than it takes to download, install, and
understand a dedicated string library. In fact I want to see a
single experienced programmer who hasn't written his own little
string library at some point in his career -- be it as a
homework assignment or just to kill time on a rainy weekend.

All these points are moot anyway -- it is very likely that the
people manipulating millions of tiny string needs a completely
different library than the huge-document-in-memory crowd. For
obvious reason, there is no one-size-fits-all solution.

robert
 
R

Robert Latest

Maybe I'm just too slow, too kind-hearted, too patient, or I gave
Jacob Navier too much credit because he backs up his ideas about
what C should look like by having written an actual piece of
softwar that implements his views. But the following exchange
that just took place convinced me that Jacob Navier is indeed a
full-blown, pathological fuckwit:

-----

JN:
It just makes NO SENSE. The same thing when you apply the addition
operator to dates: it makes NO SENSE to ADD dates.

RT:
mid_date = (start_date + end_date) / 2;

JN:
You obviously meant:
mid_date = (end_date - start_date)/2

RT:
No I didn't. That is something completely different.
(end_date - start_date) / 2 would give me half the interval
between the dates, but that is not what I wanted. I wanted the
average of the dates, which is a date.

JT:
Ahh ok, you mean then
mid_date = startdate + (end_date-start_date)/2
 
B

Ben C

Then I have completely misunderstood your point, which wouldn't be a first
for me.

The original point was just that if you want the "full power" of
operator-overloading, combined with manual memory management, you also
need constructors, destructors and references. Or something like them.

That's all. Whether C should be extended with any or all of:

1. operator overloading
2. references
3. constructors and destructors

is a matter of opinion.
 
R

Robert Latest

But the following exchange
that just took place convinced me that Jacob Navier is indeed a
full-blown, pathological fuckwit:

Actually I think I did do Jacob injustice here because the
expressions

(start_date + end_date) / 2 (1)

and

start_date + (end_date - start_date) / 2 (2)

are indeed not equivalent if the date type behaves like a pointer
type in C, as it should. (1) is invalid, (2) is valid, as can be
demonstrated by trying to compile this program:

-----
int main(void)
{
char array[100];
char *s, *e, *m;

s = array;
e = array + sizeof array;

m = (s + e) / 2;

m = s + (e - s) / 2;

return 0;
}
 
R

Richard Tobin

Robert Latest said:
Actually I think I did do Jacob injustice here because the
expressions

(start_date + end_date) / 2 (1)

and

start_date + (end_date - start_date) / 2 (2)

are indeed not equivalent if the date type behaves like a pointer
type in C, as it should. (1) is invalid, (2) is valid

Yes, of course. My objection is not to date (or pointer) addition
being disallowed, it's to the claim that it's *meaningless*. The
second expression above is a workaround for the fact that the first
one is illegal, but the fact that one can come up with a workaround
proves that the original wasn't meaningless. If it didn't mean
anything, you couldn't come up with an alternative to express the same
thing!

-- Richard
 
R

Richard Tobin

Joe Wright said:
Adding date values is nonsense.

Why? The averaging example I gave shows a perfectly clear use of it.

It might be nonsense to claim that adding date values gives you a
date, but that's not what I said.

Another analogy: I have heard it claimed that adding celsius
temperatures is nonsense, yet people do it all the time when averaging
temperatures.

-- Richard
 

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
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top