NULL and zeros

M

Mark McIntyre

If I recall correctly, Frederick prefers ``char unsigned''
because this is the ordering in Irish.

<sarcasm>Yeah, right. </>

Please note I have no opinion on Frederick's prefrence for the order
of keywords. I'm only commenting on his attempts to dig a deeper hole.
Frederick is a ``non-English'' speaker although he is not a
``non-English-speaker'' (note the hyphens).

So what? I'm non-English too. Does that mean I can put perverse
meanings on words? Goody.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Y

Yevgen Muntyan

Keith said:
Code that initializes pointers using calloc(), even if it's in some
library, is not portable; it will fail on any system where
all-bits-zero is not a null pointer.

Did I say it is portable or that the library does that? I was arguing to

You indeed can call calloc() in strictly portable C. Maybe "allocates
an object" is not correct wording, I thought it's a synonym of
"allocates memory" and is separated from object initialization.
Quite possibly that code doesn't *need* to be portable. Working only
on systems where all-bits-zero is a null pointer (and all-bits-zero is
0.0 for floating-point types) may be good enough. (I hope that the
library's documentation mentions this restriction.)

What library does is it allocates memory using calloc() and passes the
result to me; it is portable and documented. What I do to that memory is
my job, and I indeed do evil things (or don't do good things rather).
Just want to make sure noone gets an impression glib is that stupid.
Though of course everyone is free to read it as he wants to ;)
If you want to write and/or use non-portable code, you're absolutely
free to do so, but there is a cost. First, of course, it's
non-portable, and it won't work on some systems; you may never
encounter such a system in real life, but we can't guess what the next
fad in computer architecture may look like. Second, there are limits
to how much help you can get in this newsgroup. We know standard C,
as defined by the standard; we don't know the vagaries of every system
out there.

Yep, bananas are bananas, as discussed already along with who's Hitler
and nazis, and whatever Webster else :)

Regards,
Yevgen
 
M

Mark McIntyre

Charles Richmond said:


Have you a source? I know several people who would be delighted to nail that
quotation down at last. (I knew, as they did not, that it was almost
certainly *not* Edmund Burke, even though he normally seems to be the one
getting the attrib, but I had no idea it was Cicero!)

Its actually Edward Bulwer-Lytton (I kid you not) in a play entitled
"Richelieu, or the Conspiracy" published in around 1830.

He also penned "It was a dark and stormy night..." and is justly
famous as a really terrible author.




--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
D

Default User

Keith said:
Then you should look up the word "perverse" in a dictionary. Perhaps
you're confusing it with the word "perverted", a word I specifically
did not use.


Why argue with Pemberton. You have to know he's a troll by now.




Brian
 
K

Keith Thompson

Yevgen Muntyan said:
Did I say it is portable or that the library does that?

I thought you had. You wrote:

The code allocating memory knows the size, it has right to call
calloc(), it's all portable.

Quite possibly I misunderstood what the library is actually trying to
do. If the library *assumes* that calloc() will properly initialize
pointer objects and floating-point objects, then it's making a
non-portable assumption. If it merely assumes that calloc() sets the
allocated memory to all-bits-zero, obviously that's ok.

Such assumptions are often implicit; there may not even be a
meaningful answer to the question of what the library is actually
assuming. If it uses calloc() to allocate memory, it may be leading
unwary users into the trap of assuming that calloc() can provide a
meaningful value for any arbitrary type, even if it doesn't make that
assumption explicitly.
 
P

pete

Charles said:
CBFalconer wrote:
In any case, it is good documentation to initialize globals
to zero explicitly. It removes any doubt that someone reading
the code may have. IMHO.

I have heard of implementations that were deficient
in their not initializing static variables by default.
Though I don't recall what these implementations were.
 
R

Richard Heathfield

Mark McIntyre said:

["The only thing necessary for the triumph of evil is that men of good will
do nothing." -- Cicero?]
Its actually Edward Bulwer-Lytton (I kid you not) in a play entitled
"Richelieu, or the Conspiracy" published in around 1830.

That's a new one on me, and it gives us four candidates:

Burke
Cicero
Browning ("A Grammarian's Funeral")
Bulwer-Lytton ("Richelieu")
 
P

pete

Keith said:
const struct foo foo_zero = { 0 };

I've been considering {0}
as a convention for initializing static variables,
to emphasize that their initial value
is going to be used.

double fs_cos(double x)
{
unsigned n, negative, sine;
double a, b, c;
static double pi = {0}, two_pi, half_pi, third_pi;

if (0 > x) {
x = -x;
}
if (DBL_MAX >= x) {
if (1 > pi) {
pi = fs_pi();
two_pi = 2 * pi;
half_pi = pi / 2;
third_pi = pi / 3;
}
 
C

Christopher Layne

Chris said:
My computer has a delete key and other wordbegone features, which I'm
quite capable of using to trim messages I'm replying to. This means
I'm not limited to an all-but-this-contiguous-sequence edit.

I'm not getting it. I'm i'm replying to just a single block that is prompting
my reply - then I see it as a useful feature that the editor places only that
block into it's buffer, if I've selected it.
 
C

Christopher Layne

Keith said:
[snip crap about Hitler]

This is comp.lang.c.  Will you please stop talking about Hitler
here?

Huh? Weren't you and Keith JUST doing that?
 
Y

Yevgen Muntyan

Keith said:
I thought you had. You wrote:

The code allocating memory knows the size, it has right to call
calloc(), it's all portable.

Quite possibly I misunderstood what the library is actually trying to
do. If the library *assumes* that calloc() will properly initialize
pointer objects and floating-point objects, then it's making a
non-portable assumption. If it merely assumes that calloc() sets the
allocated memory to all-bits-zero, obviously that's ok.

The library doesn't assume anything here, it merely allocates memory.
It uses calloc() for practical reasons (well-defined nice behaviour on
"most" platforms); and it is documented that memory is zeroed, no more
no less.
Such assumptions are often implicit; there may not even be a
meaningful answer to the question of what the library is actually
assuming. If it uses calloc() to allocate memory, it may be leading
unwary users into the trap of assuming that calloc() can provide a
meaningful value for any arbitrary type, even if it doesn't make that
assumption explicitly.

True. But, it's not the library that creates this trap, it's life.
You know, it's like number of bits in a byte. Everybody knows that's
8 :)

(No need to repeat again and again that there platforms where a byte
is not 8 bits. It's not to you, Keith)

Regards,
Yevgen
 
K

Keith Thompson

pete said:
I've been considering {0}
as a convention for initializing static variables,
to emphasize that their initial value
is going to be used.

double fs_cos(double x)
{
unsigned n, negative, sine;
double a, b, c;
static double pi = {0}, two_pi, half_pi, third_pi;

if (0 > x) {
x = -x;
}
if (DBL_MAX >= x) {
if (1 > pi) {
pi = fs_pi();
two_pi = 2 * pi;
half_pi = pi / 2;
third_pi = pi / 3;
}

That's certainly valid, but here's how I'd do it.

Your variable pi is serving two purposes: it's holding the value of
the mathematical constant pi, and it's being used as a flag to specify
whether it and several other static objects have been initialized.
Instead, I'd declare a separate flag variable for the purpose:

double fs_cos(double x)
{
unsigned n, negative, sine;
double a, b, c;

static int initialized;
static double pi, two_pi, half_pi, third_pi;

if (x < 0.0) {
x = -x;
}
if (x <= DBL_MAX) {
if (!initialized) {
pi = fs_pi();
two_pi = 2.0 * pi;
half_pi = pi / 2.0;
third_pi = pi / 3.0;
initialized = 1;
}
/* ... */
}
/* ... */
}

I'd probably use bool rather than int if I could be sure of a
conforming C99 implementation.

(I also snuck in a few stylistic changes, which you're free to ignore.)
 
P

pete

Keith said:
That's certainly valid, but here's how I'd do it.

Your variable pi is serving two purposes: it's holding the value of
the mathematical constant pi, and it's being used as a flag to specify
whether it and several other static objects have been initialized.
Instead, I'd declare a separate flag variable for the purpose:

That's a good idea.
 
R

Rod Pemberton

Default User said:
Why argue with Pemberton. You have to know he's a troll by now.

Brian Rodenborn,

I state the truth. If you believe it to be biased, provide a better counter
example. Keith couldn't and you most likely won't...

You, and others like Mark McIntyre, have never post anything related to C.
You're always insulting people (calling them trolls or worse) and attempting
to incite anger in others. That fits the definition of a "troll" much
better than your inane descriptions.

Obsequium parit amicos; veritas parit odium. - Cicero


Rod Pemberton

PS. When will you be brave enough to use your lastname?
 
K

Keith Thompson

Rod Pemberton said:
I state the truth. If you believe it to be biased, provide a better counter
example. Keith couldn't and you most likely won't...

I didn't "provide a better counter example" because I've given up
arguing with you. If you want to think you've won the argument, knock
yourself out.
 
R

Rod Pemberton

Richard Heathfield said:
Mark McIntyre said:

["The only thing necessary for the triumph of evil is that men of good will
do nothing." -- Cicero?]
Its actually Edward Bulwer-Lytton (I kid you not) in a play entitled
"Richelieu, or the Conspiracy" published in around 1830.

That's a new one on me, and it gives us four candidates:

Burke
Cicero
Browning ("A Grammarian's Funeral")
Bulwer-Lytton ("Richelieu")

This page says it wasn't Burke but an erroneous editor of Bartlett's
quotations:
http://www.tartarus.org/~martin/essays/burkequote2.html

The online versions of Robert Browning's "A Grammarian's Funeral" don't
contain anything remotely close. It doesn't even have the words "evil" and
"triumph."

I didn't find anything in remotely close in the online English versions of
Cicero's works (partial works) and I don't read Latin (complete works).

A similar quote has also been attributed to Thomas Jefferson. Jefferson
enjoyed, i.e., "quoted," the works of Aristotle, Cicero, Locke, and Sidney
(i.e., more candidates to search).

As for the online version of Richelieu:
Richelieu : or, The conspiracy. A play, in five acts. By Sir Edward Lytton
Bulwer.
Author: Lytton, Edward Bulwer Lytton, Baron, 1803-1873.
Publication Info: New York,: Wheat & Cornett, 1875.

It doesn't have a similar quote either. There are two mentions of the word
'evil' and one of the word 'triumph' in Act 3 Scene 1. The second one, "I
have wrought great uses out of evil tools" is supposedly the "The only thing
necessary for the triumph of evil is for good men to do nothing" quote:

Act iii sc. 1 (evil)
When I am dust, my name shall, like a star,
Shine through wan space, a glory -- and a prophet
Whereby pale seers shall from their aery towers
Con all the ominous signs, benign or evil,
That make the potent astrologue of kings.

Act iii sc. 1 (evil) (evil is at roughly l. 49)
Our errors, the anatomists of schools
Can make our memory hideous!
I have wrought
Great uses out of evil tools -- and they,
In the time to come, may bask beneath the light
Which I have stolen from the angry gods,
And warn their sons against the glorious theft,
Forgetful of the darkness which it broke.

Act iii sc. 1 (triumph)
Francois. Bless you, my lord,
For that one smile! I'll wear it on my heart
To light me back to triumph. [Exit.


The other verses in Richelieu with 'evil' and 'triumph' seem to be just as
unrelated.


Rod Pemberton
 
R

Richard Tobin

That's a new one on me, and it gives us four candidates:

Burke
Cicero
Browning ("A Grammarian's Funeral")
Bulwer-Lytton ("Richelieu")

The Oxford Dictionary of Quotations says "attributed (in a number of forms)
to Burke, but not found in his writings".

-- Richard
 
F

Flash Gordon

pete said:
I have heard of implementations that were deficient
in their not initializing static variables by default.
Though I don't recall what these implementations were.

The versions of the Texas Instruments TI320C2x/2xx/5x compiler that I
used did not initialise statics when no initialiser was provided. IIRC
it was about version 6.4 or so. Since they provided the startup code
specifically so you could modify it and I had a requirement to do a
power-on RAM test, I modified my RAM test to initialise all of RAM to 0
thus rectifying this problem.
 
D

Default User

Keith said:
I didn't "provide a better counter example" because I've given up
arguing with you. If you want to think you've won the argument, knock
yourself out.

I'll Pemberton that I have killfiled him. There's little point in
replying to me, as I won't see the message unless they're quoted (like
here) and I certainly won't be responding to them.

He's a troll, pure a simple. He knows a bit about C and uses that to
aid in trolling. It would be best if people generally ignored him,
except for clinical corrections of his misstatements of fact to others.
Engaging him in debate is, in my opinion, a poor idea.




Brian
 
C

Charles Richmond

Richard said:
Charles Richmond said:


Have you a source? I know several people who would be delighted to nail that
quotation down at last. (I knew, as they did not, that it was almost
certainly *not* Edmund Burke, even though he normally seems to be the one
getting the attrib, but I had no idea it was Cicero!)
The short answer is "no"...I got the quote from some other
person and have *no* authoritative source for the attribution
to Cicero.

Please note that the "Cicero" quote says "men of good will
do nothing" and the one often attributed to Edmund Burke says
"good men do nothing". I think this is significant. Many folks
may be men of good will, but who can consider himself truly
good???
 

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,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top