473,465 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Bug/Gross InEfficiency in HeathField's fgetline program

The function below is from Richard HeathField's fgetline program. For
some reason, it makes three passes through the string (a strlen(), a
strcpy() then another pass to change dots) when two would clearly be
sufficient. This could lead to unnecessarily bad performance on very
long strings. It is also written in a hard-to-read and clunky style.

char *dot_to_underscore(const char *s)
{
char *t = malloc(strlen(s) + 1);
if(t != NULL)
{
char *u;
strcpy(t, s);
u = t;
while(*u)
{
if(*u == '.')
{
*u = '_';
}
++u;
}
}
return
t;
}

Proposed solution:

char *dot_to_underscore(const char *s)
{
char *t, *u;
if(t=u=malloc(strlen(s)+1))
while(*u++=(*s=='.' ? s++, '_' : *s++));
return t;
}

Oct 7 '07
334 11249
Tor Rustad said:
Richard Heathfield wrote:
>Tor Rustad said:
>>>
FYI, calculations using rounding, are not done *exactly*.

Fine, but we're actually talking about different things. I'm talking
about "calculations needed for double entry bookkeeping". You are
talking about "calculations needed for currency conversion". These are
two different ideas.

Methinks, you initially only considered single currency. :)
Yes, that's right, I did. And the introduction of a discussion of multiple
currencies blurred the issue in my mind for a little while. Taking a step
back and thinking about it, I realised it represented a completely
separate issue.

I still stand by my statement that you can do double-entry book-keeping
*exactly*.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 3 '07 #251
Keith Thompson wrote, On 03/11/07 18:00:
"Malcolm McLean" <re*******@btinternet.comwrites:
[...]
>You can use a double to hold integers. It has got several advantages,
such as being able to hold more digits of precision than a 32 bit
type, degrading gracefully under hyperinflation
The only degradation an accountant would consider graceful would be an
error message along the lines of, "I am most terribly sorry but your
finances are beyond my humble capacity to compute."
- it will no longer
>give exact results, of course,
In other words incorrect and leading to the company submitting them as
accounts or using them for any of a number of other purposes being find
large (to the company) amounts of money.
but if there are 6 trillion dollars to
>the pound that will be the least of any American's worries - and
giving you a free check that rounding has actually been applied.

As I understand it, inexact results in monetary calculations are
*never* acceptable.
Correct. If the tax returns are found to be incorrect that can lead to
large fines. If you submit accounts that are incorrect you can get
fined. If you sell the SW that is provably at fault in such cases then
the company could pursue you for damages.
Using a floating-point type might give you an
acceptable range over which exact values can be represented,
Yes, and people have actually used double for precisely that reason.
but if
you go outside that range you *silently* get inexact results.

In a typical modern implementation, both double and long long are 64
bits -- but long long doesn't waste bits on an exponent, and can
therefore represent a much wider range of integer values exactly.
Many implementations that don't support long long nevertheless support
a 64-bit integer type by another name.
Agreed. Having a 64 bit integer type available when you need it is very
useful. Having fixed point arithmetic (especially fixed decimal point
rather than binary point) would also be very useful, more useful for me
that a lot of what went in to C99 ;-).
--
Flash Gordon
Nov 3 '07 #252
"Flash Gordon" <sp**@flash-gordon.me.ukwrote in message
>
Correct. If the tax returns are found to be incorrect that can lead to
large fines. If you submit accounts that are incorrect you can get fined.
If you sell the SW that is provably at fault in such cases then the
company could pursue you for damages.
The British Inland Revenue doesn't care about odd pennies. It might be
different in other jurisdictions.
Accountants do, but for internal quality control purposes.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Nov 3 '07 #253
Malcolm McLean wrote, On 03/11/07 23:44:
"Flash Gordon" <sp**@flash-gordon.me.ukwrote in message
>>
Correct. If the tax returns are found to be incorrect that can lead to
large fines. If you submit accounts that are incorrect you can get
fined. If you sell the SW that is provably at fault in such cases then
the company could pursue you for damages.
The British Inland Revenue doesn't care about odd pennies. It might be
different in other jurisdictions.
My SW sends data direct to HMRC and they *do* care about pennies, just
not in the way you might expect. On certain returns you are *required*
to specify pounds and pence and the pence are *required* to be .00, and
they specify the rounding (which is down) that you are *required* to
use. Getting the pounds wrong (and you only have to be one penny out to
do that sometimes) is not permitted.

Also, pennies add up to a lot of money.
Accountants do, but for internal quality control purposes.
They care for more than that since the pennies add up.

Also, this was with reference to using floating point numbers in
financial SW and what happens when you get beyond the range that can be
accurately represented, that can lead to errors far larger than pennies.
--
Flash Gordon
Nov 4 '07 #254
On Sat, 20 Oct 2007 14:54:08 +0200, "Charlie Gordon"
<ne**@chqrlie.orgwrote:
"Richard Heathfield" <rj*@see.sig.invalida écrit dans le message de news:
So ban pointers. They cause far more trouble than strncpy.

strncpy can be banned with no downside.
Or only a very tiny one. Which I for one would be happy to accept.
Pointers are a fundamental feature of the language.
That's true.
The class of problems that can be solved without them has
a topological measure of zero.
I'm not absolutely certain what you meant here. From my brief and
long-ago exposure to topology I am under the impression that it deals
(or did) with binary/Boolean connectedness, not things that would
reasonably be called measures. I did pass briefly by measures in some
other branches of mathematics, in some of which measure zero was,
counterintuitively, actually quite large.

But from context I think you meant something like 'tiny' or
'negligible'. If so, that's not strictly true. You can implement any
finite set of finite arrays by things more or less like:

/* double x [N]; being simulated */
double getx (size_t i) {
if( i == 0 ) return x0;
else if( i == 1 ) return x1;
else if( i == 2 ) return x2;
/* else's not actually needed but included for symmetry */
... }
void putx (size_t i, double v) {
if( i == 0 ) x0 = v;
else if( i == 1 ) x1 = v;
... }

and you can either implement 'reference' parameters to functions in a
similar way, with a smaller set of larger aggregates, or by having the
caller(s) copy in and out, as in classic BASIC(s).

These aren't GOOD solutions; in fact they're atrocious. But they are
solutions, and thus formally put those problems in the 'solved' class.
(Leaving aside that formally, in the C abstract machine, function
calls, even of specific functions, use a function pointer value. But
the discussion as I understood it was about data pointers. Plus in
practice calls to specific functions are almost(?) always implemented
as direct calls, with no pointer. Sometimes a stub or jacket, but
those can't 'point' to more than one routine and so can't really
semantically be considered pointers.)

- formerly david.thompson1 || achar(64) || worldnet.att.net
Nov 4 '07 #255

"David Thompson" <da************@verizon.netwrote in message
[ programs without pointers ]
But from context I think you meant something like 'tiny' or
'negligible'. If so, that's not strictly true. You can implement any
finite set of finite arrays by things more or less like:

/* double x [N]; being simulated */
double getx (size_t i) {
if( i == 0 ) return x0;
else if( i == 1 ) return x1;
else if( i == 2 ) return x2;
/* else's not actually needed but included for symmetry */
... }
As long as you've got an input and and output statement, you can in fact
implement any program without pointers. That's a fundamental theorem.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Nov 5 '07 #256
Malcolm McLean wrote, On 05/11/07 00:10:
>
"David Thompson" <da************@verizon.netwrote in message
[ programs without pointers ]
>But from context I think you meant something like 'tiny' or
'negligible'. If so, that's not strictly true. You can implement any
finite set of finite arrays by things more or less like:

/* double x [N]; being simulated */
double getx (size_t i) {
if( i == 0 ) return x0;
else if( i == 1 ) return x1;
else if( i == 2 ) return x2;
/* else's not actually needed but included for symmetry */
... }
As long as you've got an input and and output statement,
Which in C use pointers, so you can only use them by using pointers.
After all, stdin, stdout and stderr are pointers and when you call a
function you are using a pointer to a function.
you can in fact
implement any program without pointers.
In ALL languages? Even one where the only way to do input or output
involves using a pointer?
That's a fundamental theorem.
It is easy to prove that it is incorrect for at least one language.
--
Flash Gordon
Nov 5 '07 #257
Chris Dollin said:

<snip>
Richard is referring (if I am not mistaken) to the Church-Turing
/thesis/.
Indeed.
So you're right:
Natch. :-)
it's not a theorem. (Off-hand, I recall it as too
informal to realistically expect a /proof/ of it.)

I don't think your position that unproved statements cannot be theorems
is sound, however, even if one discounts the fact that names that look
like descriptions need not be accurate labels.
This, however, is interesting. If I'm wrong, two useful things happen:

1) I get egg all over my face for incorrectly tweaking RB's nose;
2) I learn something.

Nevertheless, alas, I am not yet convinced that I am wrong. Not being a
mathematician, I have little recourse but to look at the mathematical
equivalent of Wikipedia and hope that it's a bit more accurate. Here is
what it has to say about theorems:

"A theorem is a statement that can be demonstrated to be true by accepted
mathematical operations and arguments. In general, a theorem is an
embodiment of some general principle that makes it part of a larger
theory. The process of showing a theorem to be correct is called a proof."

The case for the defence rests, m'lud.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 5 '07 #258
[citation needed!]

Richard Heathfield said:
Nevertheless, alas, I am not yet convinced that I am wrong. Not being a
mathematician, I have little recourse but to look at the mathematical
equivalent of Wikipedia
....by which I was intending to refer to "mathworld.wolfram.com" - apologies
for the omission.
and hope that it's a bit more accurate
(that is, more accurate than the Wikipedia equivalent of Wikipedia!)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 5 '07 #259
On Nov 3, 2:54 pm, Richard Heathfield <r...@see.sig.invalidwrote:
Tor Rustad said:
Richard Heathfield wrote:
Tor Rustad said:
>FYI, calculations using rounding, are not done *exactly*.
Fine, but we're actually talking about different things. I'm talking
about "calculations needed for double entry bookkeeping". You are
talking about "calculations needed for currency conversion". These are
two different ideas.
Methinks, you initially only considered single currency. :)

Yes, that's right, I did. And the introduction of a discussion of multiple
currencies blurred the issue in my mind for a little while. Taking a step
back and thinking about it, I realised it represented a completely
separate issue.

I still stand by my statement that you can do double-entry book-keeping
*exactly*.
I disagree. If there are any rational or exponential calculations,
then it is not possible.
Examples:
Depreciation calculations
Interest calculations
Investments (Future value, Present value, Annuities...)

Nov 5 '07 #260
Chris Dollin wrote:
>
Richard Heathfield wrote:
Oh my dear chap,
you're beginning to make a bit of a habit of being wrong,
aren't you? If it's a theorem, it *has* been proved.
If it has not been proved, it is not a theorem.

Richard is referring (if I am not mistaken)
to the Church-Turing /thesis/.
I don't know about that, but my entire tenth grade math education
consisted of memorizing a few axioms
and proofs of ten fundamental theorems,
which I then used to proove other theorems
and so on and so forth, for the rest of the year.

In physics the following year,
I learned of the hierarchy of observation, conjecture,
hypothesis, theory, and law;
in which "theories"
are not generally considered to have been prooven.

--
pete
Nov 5 '07 #261

"Flash Gordon" <sp**@flash-gordon.me.ukwrote in message
That theorem I know, I just did not make the connection from what Malcolm
said. However, has anyone proved that C without pointers is Turing
complete? If not, then that needs to be done before Malcolm can use that
theorem.
You need IO. However we can easily write a Turing machine in C using an
array, an index, and a set of states.
We can then implement a C interpreter with our Turing machine, and so we can
run programs written with pointers.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Nov 5 '07 #262
J. J. Farrell wrote:
>
Why do you insist on making a fool of yourself with silly sarcasm like
this? You've found evidence that Heathfield's statement was wrong, and
you've presented it. Why follow it with this ridiculous nonsense? Crow
about proving him wrong if you like, but parading this big chip on your
shoulder just makes you look daft.
Well... you have a bit of truth here. The problem is that
I have the last discussions in my mind, and I can't
abstract from them so easily.

Last time Mr Heathfield got carried away saying that strncmp
wasn't a string copy function... Incredible. When confronted
with evidence from the standard text, and from the semantics of
strncmp he argued that away. What surprised me was that nobody
(besides santosh) was ready to contradict him.

Now, this theorem stuff is much more milder (it could be
just a stupid remark somewhere) but again, only a few
people dare contradict Him (with guru uppercase).

Anyway, maybe just taking a bit of fresh air will do
a good thing to forget c.l.c and discuss normally.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 5 '07 #263
user923005 said:
On Nov 3, 2:54 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>[...] the introduction of a discussion of
multiple currencies blurred the issue in my mind for a little while.
Taking a step back and thinking about it, I realised it represented a
completely separate issue.

I still stand by my statement that you can do double-entry book-keeping
*exactly*.

I disagree. If there are any rational or exponential calculations,
then it is not possible.
Examples:
Depreciation calculations
Interest calculations
Investments (Future value, Present value, Annuities...)
Yes, but it's the same blurring. The "how much interest should be added?"
question cannot be answered exactly (except by chance, of course) - it
must be rounded. But double-entry book-keeping is about putting one
*monetary* amount into two ledgers, once on the debit side and once on the
credit side. This can be done exactly.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 5 '07 #264
pete said:
Chris Dollin wrote:
>>
Richard Heathfield wrote:
Oh my dear chap,
you're beginning to make a bit of a habit of being wrong,
aren't you? If it's a theorem, it *has* been proved.
If it has not been proved, it is not a theorem.

Richard is referring (if I am not mistaken)
to the Church-Turing /thesis/.

I don't know about that, but my entire tenth grade math education
consisted of memorizing a few axioms
and proofs of ten fundamental theorems,
which I then used to proove other theorems
and so on and so forth, for the rest of the year.

In physics the following year,
I learned of the hierarchy of observation, conjecture,
hypothesis, theory, and law;
in which "theories"
are not generally considered to have been prooven.
Yes, but there is a difference between a "theory" (which is a science
concept) and a "theorem" (which is a formal systems concept).

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 5 '07 #265
J. J. Farrell said:
jacob navia wrote:
<snip>
>>
Wikipedia says:
"... On the other hand, a deep theorem may be simply stated, but its
proof may involve surprising and subtle connections between disparate
areas of mathematics. Fermat's last theorem is a particularly well-known
example of such a theorem"

Of course Wikipedia is nothing... but the evil empire
says:
http://encarta.msn.com/encyclopedia_...7/Theorem.html
<quote>
Theorem, proposition or formula in mathematics or logic that is provable
from a set of postulates and basic assumptions
<end quote>

But OF COURSE in c.l.c the ONLY opinion that counts is the opinion
of Heathfield even if he says nonsense or make affirmations
without any proof like above.

Why do you insist on making a fool of yourself with silly sarcasm like
this? You've found evidence that Heathfield's statement was wrong,
....evidence, perhaps, but not proof. On the subject of mathematics, I'd
back Wolfram over Encarta or Wikipedia any day of the week. I'd also back
mathematicians such as Douglas Hofstadter over those sources. Here is his
definition of "theorem": "It means some statement in ordinary language
which has been proven to be true by a rigorous argument" - if Jacob Navia
wishes to argue with Hofstadter's and Wolfram's position on the matter,
that's up to him, but to claim that it is my *opinion* is simply wrong,
just as it would be wrong to say that it's my *opinion* that Dennis
Ritchie's middle initial is M.

Please also note that, whatever Mr Navia seems to think, I have never
claimed (unless, perhaps, in jest) that my opinion is normative in this
newsgroup.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #266
user923005 said:

<snip>
Actually, I agree with Jacob here. Here is a mathematical definition
of theorem, and I think it agrees with the general sense:
http://mathworld.wolfram.com/Theorem.html
That is precisely the source that I quoted upthread. So you agree with me,
and you agree with Jacob. Therefore, Jacob agrees with me. QED.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #267
Malcolm McLean wrote, On 05/11/07 21:54:
>
"Flash Gordon" <sp**@flash-gordon.me.ukwrote in message
>That theorem I know, I just did not make the connection from what
Malcolm said. However, has anyone proved that C without pointers is
Turing complete? If not, then that needs to be done before Malcolm can
use that theorem.
You need IO. However we can easily write a Turing machine in C using an
array, an index, and a set of states.
When you use the array name it decays to a pointer, so you are still
using pointers.
We can then implement a C interpreter with our Turing machine, and so we
can run programs written with pointers.
Apart from the fact you have just used a pointer according to the
definition of the C language, since array indexing is defined in terms
of pointer arithmetic.
--
Flash Gordon
Nov 6 '07 #268
jacob navia <ja***@nospam.comwrites:
J. J. Farrell wrote:
>Why do you insist on making a fool of yourself with silly sarcasm
like this? You've found evidence that Heathfield's statement was
wrong, and you've presented it. Why follow it with this ridiculous
nonsense? Crow about proving him wrong if you like, but parading
this big chip on your shoulder just makes you look daft.

Well... you have a bit of truth here. The problem is that
I have the last discussions in my mind, and I can't
abstract from them so easily.
Try harder.
Last time Mr Heathfield got carried away saying that strncmp
wasn't a string copy function... Incredible. When confronted
with evidence from the standard text, and from the semantics of
strncmp he argued that away. What surprised me was that nobody
(besides santosh) was ready to contradict him.
Neither of the first two arguments to strncpy() needs to be a pointer
to a string. The fact that its name starts with "str", or that it's
in the "String handling" section of the standard, doesn't make it a
string function.

How exactly do you define the term "string function"?
Now, this theorem stuff is much more milder (it could be
just a stupid remark somewhere) but again, only a few
people dare contradict Him (with guru uppercase).
Oh, good grief. There seem to be several different definitions of the
word "theorem". Richard's statement may or may not have been 100%
correct, but it was not unreasonable.

People tend not to agree with Richard Heathfield when he's right.
Anyway, maybe just taking a bit of fresh air will do
a good thing to forget c.l.c and discuss normally.
Good idea.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 6 '07 #269
Keith Thompson said:

<snip>
People tend not to agree with Richard Heathfield when he's right.
Yeah, I noticed that too.

Unfortunately, they don't agree with me when I'm wrong, either. If they
did, life would be so much simpler.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #270
user923005 <dc*****@connx.comwrites:
I still stand by my statement that you can do double-entry book-keeping
*exactly*.

I disagree. If there are any rational or exponential calculations,
then it is not possible.
Examples:
Depreciation calculations
Interest calculations
Investments (Future value, Present value, Annuities...)
My impression was that there are reglementary texts who precise exactly how
those should be computed, included the rounding rules.

BTW, I doubt very much that they have any relationship with the rounding
rules of any implementation of floating point, even decimal FP. And we
know the problems caused by double rounding.

Yours,

--
Jean-Marc
Nov 6 '07 #271
Richard Heathfield wrote, On 05/11/07 23:40:
user923005 said:
>On Nov 3, 2:54 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>>[...] the introduction of a discussion of
multiple currencies blurred the issue in my mind for a little while.
Taking a step back and thinking about it, I realised it represented a
completely separate issue.

I still stand by my statement that you can do double-entry book-keeping
*exactly*.
I disagree. If there are any rational or exponential calculations,
then it is not possible.
Examples:
Depreciation calculations
Interest calculations
Investments (Future value, Present value, Annuities...)

Yes, but it's the same blurring. The "how much interest should be added?"
question cannot be answered exactly (except by chance, of course) - it
must be rounded.
In the case of interest calculations (an a lot of other financial
calculations), the rounding is actually part of the definition of the
algorithm you are required to use in calculating the new value. So it
can be argued that such calculations always provide an exact answer.
But double-entry book-keeping is about putting one
*monetary* amount into two ledgers, once on the debit side and once on the
credit side. This can be done exactly.
Not only can, but is actually required to be done exactly.
--
Flash Gordon
Nov 6 '07 #272
Flash Gordon said:
Richard Heathfield wrote, On 05/11/07 23:40:
<snip>
>But double-entry book-keeping is about putting one
*monetary* amount into two ledgers, once on the debit side and once on
the credit side. This can be done exactly.

Not only can, but is actually required to be done exactly.
THANK you! At last someone sees what I'm getting at. I was beginning to
despair of my ability to explain this.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #273
On Mon, 05 Nov 2007 22:53:11 +0100, jacob navia <ja***@nospam.com>
wrote:
>http://dictionary.reference.com/browse/theorem
<snip>
>
Can you read?
"something to be proved from other propositions or formulas" (1)
I'll see your dictionary and raise you one:

http://www.askoxford.com/concise_oed/theorem?view=uk

"a general proposition not self-evident but proved by a chain of
reasoning"
--
PGP key ID 0xEB7180EC
Nov 6 '07 #274
Richard Heathfield <rj*@see.sig.invalidwrites:
Keith Thompson said:
<snip>
>People tend not to agree with Richard Heathfield when he's right.

Yeah, I noticed that too.

Unfortunately, they don't agree with me when I'm wrong, either. If they
did, life would be so much simpler.
Argh! What I meant was

People tend not to *disagree* with Richard Heathfield when he's
right.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 6 '07 #275
On Tuesday 06 Nov 2007 3:26 pm Keith Thompson <ks***@mib.orgwrote in
article <ln************@nuthaus.mib.org>:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Keith Thompson said:
<snip>
>>People tend not to agree with Richard Heathfield when he's right.

Yeah, I noticed that too.

Unfortunately, they don't agree with me when I'm wrong, either. If
they did, life would be so much simpler.

Argh! What I meant was

People tend not to *disagree* with Richard Heathfield when he's
right.
Wonder how Richard will respond to this one now? :)

Perhaps replace the word "agree" above with "disagree"?

Nov 6 '07 #276
In article <11**********************@q3g2000prf.googlegroups. com>,
William Hughes <wp*******@hotmail.comwrote:
>How many legs does a horse have if you call a tail
a leg? Four, calling a tail a leg does not make a tail
a leg.
It makes "leg" refer to tails as well as legs, so that the statement
"a horse has five legs" becomes true.

Language is mutable, even if horses aren't.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 6 '07 #277
Keith Thompson said:

<snip>
Argh! What I meant was

People tend not to *disagree* with Richard Heathfield when he's
right.
Oh! :-) Well, that's partly true, but there are plenty of counter-examples
right here in this newsgroup - people who continue to believe I'm wrong,
long after I've demonstrated otherwise.

Name names? What's the point? They know who I mean.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #278
Richard Tobin said:
In article <11**********************@q3g2000prf.googlegroups. com>,
William Hughes <wp*******@hotmail.comwrote:
>>How many legs does a horse have if you call a tail
a leg? Four, calling a tail a leg does not make a tail
a leg.

It makes "leg" refer to tails as well as legs, so that the statement
"a horse has five legs" becomes true.

Language is mutable, even if horses aren't.
If you want to be mocked by a six-year-old, telling him or her that a horse
has five legs is a great way to start.

The statement "a horse has five legs" is false, at least for the
overwhelming majority of horses. (I know of no counter-examples.)

Calling a tail a leg does not make "leg" refer to tails as well as legs
except in the mind of the caller and those he can persuade to agree.

Language may well be mutable, but mute it too far and you risk being
misunderstood.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #279
user923005 wrote:
On Nov 5, 1:53 pm, jacob navia <ja...@nospam.comwrote:
[...]
>Then those theorems are... well "UNPROVEN" theorems. PERIOD.

Actually, I agree with Jacob here. Here is a mathematical definition
of theorem, and I think it agrees with the general sense:
http://mathworld.wolfram.com/Theorem.html
I side with R.H. on this, that is to receive the status of a *theorem*,
there should exist a proof.

If the mathematical statement is believed to be true, but no proof exist
yet, a better wording is *conjecture* or *hypothesis*.

However, a proof might not be correct, and I see no point in insisting
on formal proofs over computer assisted proofs.

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Nov 6 '07 #280
Richard Heathfield wrote:
Flash Gordon said:
>Richard Heathfield wrote, On 05/11/07 23:40:

<snip>
>>But double-entry book-keeping is about putting one
*monetary* amount into two ledgers, once on the debit side and once on
the credit side. This can be done exactly.
Not only can, but is actually required to be done exactly.

THANK you! At last someone sees what I'm getting at. I was beginning to
despair of my ability to explain this.
Tor's Theorem 1:

R.H. is not always correct, when he think he is.

Proof:

Double-entry bookkeeping, means there will be at least two accounts. For
sake of argument, let us pick a UK bank, with both sterling and euro
accounts.

The whole point about double-entry, is to detect errors and fraud, a
bank insider (with access to one account), who tries to credit an
account will probably be caught, when there is a mis-match between the
two "books" (assuming proper audit trails exists).

From the UK bank perspective, there is no way these calculations can
always be done *exactly* between multiple currencies. A book-entry in
e.g. sterling, of an euro account, need to be converted to euro at some
point in time, which typically involve the process of rounding
(following specific rules).

The obvious requirement our UK bank has, will be to match each account
at some cut-off times each day. This calculation should be done
*exactly*. If the currency conversion has already been done at this
point, there is no simple way to match the books *exactly*.

∎
Tor's Conjecture 1:

R.H. is not always correct, when he get the last word.

Proof:

\remark Soon to be known as "Tor's Theorem 2".

;-)

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Nov 6 '07 #281
Keith Thompson wrote:
jacob navia <ja***@nospam.comwrites:
>J. J. Farrell wrote:
>>Why do you insist on making a fool of yourself with silly sarcasm
like this? You've found evidence that Heathfield's statement was
wrong, and you've presented it. Why follow it with this ridiculous
nonsense? Crow about proving him wrong if you like, but parading
this big chip on your shoulder just makes you look daft.
Well... you have a bit of truth here. The problem is that
I have the last discussions in my mind, and I can't
abstract from them so easily.

Try harder.
>Last time Mr Heathfield got carried away saying that strncmp
wasn't a string copy function... Incredible. When confronted
with evidence from the standard text, and from the semantics of
strncmp he argued that away. What surprised me was that nobody
(besides santosh) was ready to contradict him.
Well, I'm one of the many people who was unwilling to contradict Mr.
Heathfield, and there's a very simple reason for that: I didn't think he
was wrong. Jacob might want to consider the possibility that many of the
other silent ones also agreed with Mr. Heathfield, even if Jacob finds
that very difficult to imagine.
Neither of the first two arguments to strncpy() needs to be a pointer
to a string.
There's also the fact that it usually either does not copy the entire
string, not even bothering to properly null-terminate it, or writes a
lot of stuff in addition. Only rarely, in normal usage, does it write an
exact copy of the string, and nothing else.

There are other plausible ways of defining what is meant by a "string
copy function", but requiring that it always copy the entire string,
including the terminating null character, and write nothing more than
the string, seems like a reasonable requirement to me.

The other issue debated about strncpy() is whether it was actually any
use. Well, in my programs I routinely face the following situation:

The output file spec allows a fixed amount of space for an array of
characters. The input data that is to be written into that space will
usually be small enough to fit, but cannot be guaranteed to fit. When it
does not fit, it's not an error condition - I'm supposed to put as many
characters from the beginning of the input source into the output array
as possible. Losing the terminating characters is regrettable but
permissible. The character array can be null-terminated, but is not
required to be. However, to make binary comparison of output files
easier, every character after the terminating null should also be null.

The above description applies to many of the "strings" that my programs
have to write, and also to many of the strings that they must read. It
seems to me that strncpy() is tailor-made for such use.
Nov 6 '07 #282
James Kuyper <ja*********@verizon.netwrites:
Keith Thompson wrote:
>jacob navia <ja***@nospam.comwrites:
>>J. J. Farrell wrote:
Why do you insist on making a fool of yourself with silly sarcasm
like this? You've found evidence that Heathfield's statement was
wrong, and you've presented it. Why follow it with this ridiculous
nonsense? Crow about proving him wrong if you like, but parading
this big chip on your shoulder just makes you look daft.
Well... you have a bit of truth here. The problem is that
I have the last discussions in my mind, and I can't
abstract from them so easily.

Try harder.
>>Last time Mr Heathfield got carried away saying that strncmp
wasn't a string copy function... Incredible. When confronted
with evidence from the standard text, and from the semantics of
strncmp he argued that away. What surprised me was that nobody
(besides santosh) was ready to contradict him.

Well, I'm one of the many people who was unwilling to contradict
Mr. Heathfield, and there's a very simple reason for that: I didn't
think he was wrong. Jacob might want to consider the possibility that
many of the other silent ones also agreed with Mr. Heathfield, even if
Jacob finds that very difficult to imagine.
That doesn't necessarily ring true.
>
>Neither of the first two arguments to strncpy() needs to be a pointer
to a string.

There's also the fact that it usually either does not copy the entire
string, not even bothering to properly null-terminate it, or writes a
"Not even bothering" what are you talking about? It is NOT supposed to.
lot of stuff in addition. Only rarely, in normal usage, does it write
an exact copy of the string, and nothing else.
Err, correct, for an exact copy we use strcpy. A different function.
>
There are other plausible ways of defining what is meant by a "string
copy function", but requiring that it always copy the entire string,
including the terminating null character, and write nothing more than
the string, seems like a reasonable requirement to me.
Yes it is reasonable. As is

,----
| The strncpy() function is similar, except that at most n bytes of src
| are copied. Warning: If there is no null byte among the first n
| bytes of src, the string placed in dest will not be null
| terminated.
`----

The "string placed in dest" is the clue.

You see what makes it so childishly simple is the "n" bit in the
name. it doesn't take a genius to figure out that n means
something. Possibly the number of characters to copy? Surely not!
>
The other issue debated about strncpy() is whether it was actually any
use. Well, in my programs I routinely face the following situation:

The output file spec allows a fixed amount of space for an array of
characters. The input data that is to be written into that space will
usually be small enough to fit, but cannot be guaranteed to fit. When
it does not fit, it's not an error condition - I'm supposed to put as
many characters from the beginning of the input source into the output
array as possible. Losing the terminating characters is regrettable
but permissible. The character array can be null-terminated, but is
not required to be. However, to make binary comparison of output files
easier, every character after the terminating null should also be
null.

The above description applies to many of the "strings" that my
programs have to write, and also to many of the strings that they must
read. It seems to me that strncpy() is tailor-made for such use.
It is nonsense to decry strncpy because some programmers can't be arsed
to read the manual properly IMO.

ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!
Nov 6 '07 #283
Tor Rustad said:
Richard Heathfield wrote:
>Flash Gordon said:
>>Richard Heathfield wrote, On 05/11/07 23:40:

<snip>
>>>But double-entry book-keeping is about putting one
*monetary* amount into two ledgers, once on the debit side and once on
the credit side. This can be done exactly.
Not only can, but is actually required to be done exactly.

THANK you! At last someone sees what I'm getting at. I was beginning to
despair of my ability to explain this.

Tor's Theorem 1:

R.H. is not always correct, when he think he is.
I can certainly accept that as a working hypothesis, and it agrees with a
fair amount of observational evidence, but I take issue with your proof.
Proof:

Double-entry bookkeeping, means there will be at least two accounts. For
sake of argument, let us pick a UK bank, with both sterling and euro
accounts.
Fine, but all the entries in the sterling account will be in sterling, and
all the entries in the Euro account will be in Euros. If a transaction
occurs between the two accounts, then it will be done at a particular
exchange rate that is prevalent at the date and time of the transaction,
and this exchange rate will be recorded for auditing purposes. Also, the
exchange rate will be applied according to strict rounding rules. When the
Euro was in the process of being introduced, the European Commission wrote
a whole pile of papers giving advice to companies on how to handle this
stuff in the accounts. I remember ploughing through them - not a task to
make a bunny happy, I assure you.
Tor's Conjecture 1:

R.H. is not always correct, when he get the last word.
Word games. The last word is yours if you want it - I'm done here.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #284
Tor Rustad wrote, On 06/11/07 11:38:
Richard Heathfield wrote:
>Flash Gordon said:
>>Richard Heathfield wrote, On 05/11/07 23:40:

<snip>
>>>But double-entry book-keeping is about putting one
*monetary* amount into two ledgers, once on the debit side and once on
the credit side. This can be done exactly.
Not only can, but is actually required to be done exactly.

THANK you! At last someone sees what I'm getting at. I was beginning
to despair of my ability to explain this.

Tor's Theorem 1:

R.H. is not always correct, when he think he is.

Proof:

Double-entry bookkeeping, means there will be at least two accounts. For
sake of argument, let us pick a UK bank, with both sterling and euro
accounts.

The whole point about double-entry, is to detect errors and fraud, a
bank insider (with access to one account), who tries to credit an
account will probably be caught, when there is a mis-match between the
two "books" (assuming proper audit trails exists).

From the UK bank perspective, there is no way these calculations can
always be done *exactly* between multiple currencies.
Yes there is.
A book-entry in
e.g. sterling, of an euro account, need to be converted to euro at some
point in time, which typically involve the process of rounding
(following specific rules).
Each account is in a specific currency and the books for that account
are kept in the currency the account is in. A person or organisation can
have multiple accounts each in a different currency. This means that the
only way to convert money from one currency to another is to move it
from one account to another, and at that point the rounding occurs as
part of the conversion using defined rules and a specified conversion
rate, and those rules specify *exactly* what will be credited to one
account and debited from the other.
The obvious requirement our UK bank has, will be to match each account
at some cut-off times each day. This calculation should be done
*exactly*. If the currency conversion has already been done at this
point, there is no simple way to match the books *exactly*.
Incorrect, it is easy as long as you follow the requirements above.

If anyone is interested enough I could ask one of my brothers who was
doing application support & maintenance for one of the large
organisations in the City of London that works with lots of currencies.
Tor's Conjecture 1:

R.H. is not always correct, when he get the last word.

Proof:

\remark Soon to be known as "Tor's Theorem 2".

;-)
I don't think that Richard believes he is always correct.
--
Flash Gordon
Nov 6 '07 #285
Flash Gordon said:

<snip>
I don't think that Richard believes he is always correct.
Interesting philosophical point there, Flash! :-)

As a matter of fact, I *do* think I'm correct, for the obvious reason that,
if I thought I were /in/correct, naturally I would modify my position.
(Doesn't everyone think that way?)

But you're right insofar as I am willing to entertain the possibility that
I could be mistaken; and if I am shown to be mistaken (as I have been, on
far more occasions than I could possibly enumerate), obviously I change my
mind, thus becoming *even more* correct than I was before! :-)

Seriously, there are people here who know far more about C than I do,
people like James K, Jack K, most if not all of the Chrises, Dann, Ben
P... and these people have corrected me (correctly!) on many occasions;
also, they frequently give correct answers to questions that I'd have got
very wrong indeed if I hadn't had the good sense to keep my fingers shut.

I guess I attract flak from the trolls because I don't suffer fools gladly,
and a troll is first and foremost a fool. (A fool is not necessarily a
troll, of course, which explains the /other/ flak I get.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #286
In article <mg************@news.individual.net>,
Richard <rg****@gmail.comwrote in response to some punter:
....
>ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!
Except that he got it backwards. The hyperventilating style assumed by
Dickie H is to refer to the people you don't like as "Mr." and the ones
you do by their full names (or, occasionally, by their first names only).
This is a fairly common hack (inter alia, in the biz world); it was by
no means invented by our own Dickie H.

The punter to which rgrdev responded couldn't even get that right, and
dropped down into schoolboy/playground-speak. On the playground, you
refer to the people in power as "Mr.", and, of course, refer to the
people you're beating up on by their first names.

Nov 6 '07 #287
Richard wrote:
....
ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!
No. I normally don't bother with "Mr." or "Mrs." for anybody, certainly
not for myself, and I routinely use first names when known, unless they
are ambiguous within the group that I'm speaking to (for example, the
multiple "Richards" who are regulars on this newsgroup). Most of the
people I deal with have no problem with that, or at least none that
they've bothered to express to me. However, I recently got reprimanded
by someone who considered it a serious insult that I didn't refer to him
as "Mr. X", whatever "X" was (I don't remember). As a reaction to that
incident, I sometimes inconsistently switch from my normal usage.
Nov 6 '07 #288
James Kuyper <ja*********@verizon.netwrites:
Richard wrote:
...
>ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!

No. I normally don't bother with "Mr." or "Mrs." for anybody,
certainly not for myself, and I routinely use first names when known,
unless they are ambiguous within the group that I'm speaking to (for
example, the multiple "Richards" who are regulars on this
I don't think it is necessary to litter a reply with names. It's all
self evident, generally, to whom one is referring thanks to a wonderful
invention called message threads and quoting.
newsgroup). Most of the people I deal with have no problem with that,
or at least none that they've bothered to express to me. However, I
recently got reprimanded by someone who considered it a serious insult
that I didn't refer to him as "Mr. X", whatever "X" was (I don't
remember). As a reaction to that incident, I sometimes inconsistently
switch from my normal usage.
Frankly I think calling anyone "Mr this" or "Mr that" is talking down
and appearing to rather take the high horse approach. As is evident from
the certain posts here.

Still, all to their own.
Nov 6 '07 #289
Keith Willis <me@privacy.netwrites:
On Mon, 05 Nov 2007 22:53:11 +0100, jacob navia <ja***@nospam.com>
wrote:
>>http://dictionary.reference.com/browse/theorem
<snip>
>>
Can you read?
"something to be proved from other propositions or formulas" (1)

I'll see your dictionary and raise you one:

http://www.askoxford.com/concise_oed/theorem?view=uk

"a general proposition not self-evident but proved by a chain of
reasoning"
....and I'll raise you to the full OED:

"a. In Mathematics and Physics; spec. in Geometry, a proposition
embodying merely something to be proved..."[1]

Presumably the argument here is whether the "loose" sense of something
asserted and not yet proved (or disproved) is in the dictionary. Of
course, the OED gives the usual, stricter, meaning above this one.

For what it is worth, I am with RH on this (despite the detail from
the dictionary) because I don't think the Church-Turing thesis can be
formulated as a theorem (or, better, a conjecture) because it is by
its nature vague about the formality.

[1] The "merely" here refers to the stronger notion of a "problem" in
geometry -- something to be done (like squaring the circle) rather
than "merely" proved or disproved.

--
Ben.
Nov 6 '07 #290
Richard wrote:
....
I don't think it is necessary to litter a reply with names. It's all
self evident, generally, to whom one is referring thanks to a wonderful
invention called message threads and quoting.
The original draft of the message in question was filled with "he" and
"him" and "his". I only replaced them with actual names when I
realized that it was often unclear who I was referring to.

Nov 6 '07 #291
ga*****@xmission.xmission.com (Kenny McCormack) writes:
In article <mg************@news.individual.net>,
Richard <rg****@gmail.comwrote in response to some punter:
...
>>ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!

Except that he got it backwards. The hyperventilating style assumed by
Dickie H is to refer to the people you don't like as "Mr." and the ones
you do by their full names (or, occasionally, by their first names only).
This is a fairly common hack (inter alia, in the biz world); it was by
no means invented by our own Dickie H.

The punter to which rgrdev responded couldn't even get that right, and
dropped down into schoolboy/playground-speak. On the playground, you
refer to the people in power as "Mr.", and, of course, refer to the
people you're beating up on by their first names.
Slight corrections : their sirnames.

As in "You 'ad enuff yet McCormack?!?!" (sound of boot going in).

Nov 6 '07 #292
"Richard" <rg****@gmail.coma écrit dans le message de news:
mg************@news.individual.net...
>
It is nonsense to decry strncpy because some programmers can't be arsed
to read the manual properly IMO.
Just reflect on this bold statement next time you are seated in an aircraft.
Wouldn't you want software to be written with less easy to misuse library
functions, *even* if 'some programmers can't be arsed to read the manual
properly' ?

--
Chqrlie.
Nov 6 '07 #293
Richard Heathfield wrote:
[snip]

1) The standard says:
7.21 String Handling
Later:
7.21.2: Copying functions
Later:
7.21.2.3: The strncpy function.

But this is no proof for Mr Heathfield. He will
insist forever his nonsense. strncpy is not
for string copying.

There is no blinder man as the one that doesn't want to see.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 6 '07 #294
Charlie Gordon said:

<snip>
Fermat claimed to have proved his conjecture, and wrote his friends about
his 'marvelous' discovery. His proof was never found,
....if it ever existed...
and thus the
'theorem' remained unproved for more than three centuries.
Right. An unpublished proof, as far as the mathematics community is
concerned, might as well not exist. I have an interesting demonstration of
this fact, but this Usenet article is too large to contain it.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 6 '07 #295
Richard Heathfield wrote, On 06/11/07 13:34:
Flash Gordon said:

<snip>
>I don't think that Richard believes he is always correct.

Interesting philosophical point there, Flash! :-)

As a matter of fact, I *do* think I'm correct, for the obvious reason that,
if I thought I were /in/correct, naturally I would modify my position.
(Doesn't everyone think that way?)
<snip>

You have misinterpreted my statement. I didn't say that you don't always
believe you are correct, I said that you don't believe you are always
correct. I.e. I stated that I believe you know that you are not perfect
and are sometimes incorrect, not that you state things that you believe
you are incorrect at the time you state them.
--
Flash gordon
Nov 6 '07 #296
On Nov 5, 3:40 pm, Richard Heathfield <r...@see.sig.invalidwrote:
user923005 said:
On Nov 3, 2:54 pm, Richard Heathfield <r...@see.sig.invalidwrote:
[...] the introduction of a discussion of
multiple currencies blurred the issue in my mind for a little while.
Taking a step back and thinking about it, I realised it represented a
completely separate issue.
I still stand by my statement that you can do double-entry book-keeping
*exactly*.
I disagree. If there are any rational or exponential calculations,
then it is not possible.
Examples:
Depreciation calculations
Interest calculations
Investments (Future value, Present value, Annuities...)

Yes, but it's the same blurring. The "how much interest should be added?"
question cannot be answered exactly (except by chance, of course) - it
must be rounded. But double-entry book-keeping is about putting one
*monetary* amount into two ledgers, once on the debit side and once on the
credit side. This can be done exactly.
I agree that the credit and the debit will agree. But the amount
stored is not exact. There have been schemes based on stealing these
fractional pennies that have netted huge sums over time.

The point I was making is that the calculations of the above enties
are definitely not exact. An 'agreed to method' such as banker's
rounding is used to truncate the decimals at some point and it is
stored. But any operation that uses something as simple as a division
is necessarily (by its very nature) not perfectly precise. The only
operations that can be performed with perfect precision in fixed point
arithmetic are addition, subtraction and multiplication. Any
calculations that include division, exponentiation, quadrature, etc.
are by their very nature not exact. All financial systems of
sufficient complexity include these types of calculations. Truncation
of the total does not vaporize the inexactness of the result. It only
masks it.

If you examine quantlib, you will find that it is full of floating
point operations. But you cannot perform this sort of analysis
correctly without it.

Nov 6 '07 #297
On Nov 5, 3:41 pm, Richard Heathfield <r...@see.sig.invalidwrote:
pete said:


Chris Dollin wrote:
Richard Heathfield wrote:
Oh my dear chap,
you're beginning to make a bit of a habit of being wrong,
aren't you? If it's a theorem, it *has* been proved.
If it has not been proved, it is not a theorem.
Richard is referring (if I am not mistaken)
to the Church-Turing /thesis/.
I don't know about that, but my entire tenth grade math education
consisted of memorizing a few axioms
and proofs of ten fundamental theorems,
which I then used to proove other theorems
and so on and so forth, for the rest of the year.
In physics the following year,
I learned of the hierarchy of observation, conjecture,
hypothesis, theory, and law;
in which "theories"
are not generally considered to have been prooven.

Yes, but there is a difference between a "theory" (which is a science
concept) and a "theorem" (which is a formal systems concept).
True, but they are closely related:
http://www.etymonline.com/index.php?...earchmode=none

theorem
1551, from M.Fr. théorème, from L.L. theorema, from Gk. theorema
"spectacle, speculation," in Euclid "proposition to be proved," from
theorein "to consider" (see theory).

Nov 6 '07 #298
On Wednesday 07 Nov 2007 12:23 am Flash Gordon <sp**@flash-gordon.me.uk>
wrote in article <6r************@news.flash-gordon.me.uk>:
Richard Heathfield wrote, On 06/11/07 13:34:
>Flash Gordon said:

<snip>
>>I don't think that Richard believes he is always correct.

Interesting philosophical point there, Flash! :-)

As a matter of fact, I *do* think I'm correct, for the obvious reason
that, if I thought I were /in/correct, naturally I would modify my
position. (Doesn't everyone think that way?)

<snip>

You have misinterpreted my statement. I didn't say that you don't
always believe you are correct, I said that you don't believe you are
always correct. I.e. I stated that I believe you know that you are not
perfect and are sometimes incorrect, not that you state things that
you believe you are incorrect at the time you state them.
This gets my vote for the most extreme hair-splitting post for this
year :)

Nov 6 '07 #299
Charlie Gordon wrote:
"James Kuyper" <ja*********@verizon.neta écrit dans le message de news:
....
There's also the fact that it usually either does not copy the entire
string, not even bothering to properly null-terminate it, or writes a lot
of stuff in addition. Only rarely, in normal usage, does it write an exact
copy of the string, and nothing else.

The fact that it does not produce a 'string' is not a necessary conditionto
qualify as a 'string function', take strlen for instance.
True, but I was specifically responding to a message referring to
"string copy" functions, not just "string" functions. A "string copy"
function that doesn't always copy the entire string, and sometimes
creates an output that is a lot larger than the string that is to be
copied is arguably mislabeled.
The other issue debated about strncpy() is whether it was actually any
use. Well, in my programs I routinely face the following situation:

The output file spec allows a fixed amount of space for an array of
characters. The input data that is to be written into that space will
usually be small enough to fit, but cannot be guaranteed to fit. When it
does not fit, it's not an error condition - I'm supposed to put as many
characters from the beginning of the input source into the output arrayas
possible. Losing the terminating characters is regrettable but
permissible. The character array can be null-terminated, but is not
required to be. However, to make binary comparison of output files easier,
every character after the terminating null should also be null.

The above description applies to many of the "strings" that my programs
have to write, and also to many of the strings that they must read. It
seems to me that strncpy() is tailor-made for such use.

You are making this up ;-)
No.
If you are dealing with binary files, strncpy is not the final answer to
your problem, you have to perform I/O as well and the intermediary bufferis
wasteful. A 'tailor-made' solution to your problem is this:
The third-party library function that performs the actual writing
requires a buffer. What actually ends up in the output file is not
just the array itself, but also the name, dimensions, and XDR datatype
of the array.

Nov 6 '07 #300

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.