why I cannot stop this loop at 50 points? (code)

B

Ben Bacarisse

CBFalconer said:
R J C wrote:

The first may not be, because time returns a time_t, but I may be
wrong here. The second is obviously correct, since the argument
for srand is cast to the appropriate form, and time(NULL) is
defined. This is valid standard C code.

Can I join those who have suggested that you read more of a thread
before replying? You'll see explanations of what is non-portable
about the second form later on.
 
K

Keith Thompson

CBFalconer said:
The first may not be, because time returns a time_t, but I may be
wrong here. The second is obviously correct, since the argument
for srand is cast to the appropriate form, and time(NULL) is
defined. This is valid standard C code.

Both are equivalent. srand() expects an argument of type unsigned;
since <time.h> is included, and therefore the prototype for srand() is
visible, the result of time() will be converted from time_t to
unsigned with or without the cast. In other words, the cast, like
most casts, is superfluous.

The problem is that time_t is only guaranteed to be an arithmetic
type. If it's a floating-point type, and the value exceeds UINT_MAX,
then the behavior of the conversion is undefined.

I think this was mentioned some time ago. I again urge you to find a
way to read an entire thread before posting a followup.
 
J

James Dow Allen

It's good to know why srand(time(NULL)) might invoke
undefined behavior, but it's a really common idiom.
It's common enough to appear (with
caveats) in the comp.lang.c FAQ.

I realize working around bad specs is an important
part of practical programming, but shouldn't we
strive to make the world a better place? Why not
find the hypothetical library that makes time() a
float and stamp it out:
"C Programmers go on strike, insisting
that foolish OS change its ways"

For that matter, why not create a new system call:
arbnum() -- returns an arbitrary integer, prob.
different from its other recent returns.

*Improving* specs is also an important part of
software engineering; why should the common sys
interface be any different just because
We_Didnt_Know_What_We_Were_Doing, Ltd. went out
of business and Budget Motels still uses their
OS in its doorknobs?

Shucks, if even the U.S. government can revise its
wrong-headed policies, why not the programming world?

James Dow Allen
 
B

Beej Jorgensen

James Dow Allen said:
*Improving* specs is also an important part of software engineering

There's some debate to be had on whether or not the Standard's broken in
this case. After all, it never suggests a source for seeding your
random number generator. Everyone just happens to use time(NULL)
because it's Tradition and it works on a huge number of machines and it
makes sense to use the time as a seed.

-Beej
 
K

Keith Thompson

James Dow Allen said:
I realize working around bad specs is an important
part of practical programming, but shouldn't we
strive to make the world a better place? Why not
find the hypothetical library that makes time() a
float and stamp it out:
"C Programmers go on strike, insisting
that foolish OS change its ways"

Yes, let's stamp it out. I'll put on my hypothetical boots right now.

I wouldn't object to a change in the standard requiring time_t to be
an integral type. In any case, I've already (more or less defended
the use of srand(time(NULL)).
For that matter, why not create a new system call:
arbnum() -- returns an arbitrary integer, prob.
different from its other recent returns.

Is "prob." supposed to be "probably"? Sounds like rand() to me. I
presume rand() doesn't actually meet your requirements; can you state
them more precisely?

[...]
 
J

James Dow Allen

Is "prob." supposed to be "probably"?  Sounds like rand() to me.  I
presume rand() doesn't actually meet your requirements; can you state
them more precisely?

Sorry, I thought it was clear in context.
I intended arbnum() as a substitute for time(0)
for the usage under discussion in this subthread, i.e.
srand(arbnum());
And no, srand(rand()) won't work! :)

Unix programmers often have an (almost) adequate
solution with srand(getpid()) but of course we
must also cater to The Operating System With
a GNP Bigger than Many Countries(tm).

James
 
G

Guest

Keep in mind that Han never stated that his objective was to "destroy" clc.
Nor did _I_ ever state that my objective was to "disrupt" clc.

Yet, the regs frequently state these things as if they were facts.

if it walks like a duck...
Thus we see that lying comes as easily as breathing for clc regs.

Keep *that* in mind when evaluating their statements.

I suggest the original poster reads some back-posts and make his
own mind up.
 
K

Kenny McCormack

if it walks like a duck...


I suggest the original poster reads some back-posts and make his
own mind up.

Indeed. Quite. I think the conclusion(s) reached will be obvious.

Also, please show me any post in which either I or Han state our "objective".
Hint: The sentence must begin with the words "My objective is".
 
K

Kenny McCormack

Of course you have. That's because your buddy Heathfield recommended
its use. You'd also defend the use of fflush(stdin) if Heathfield
recommended that. Funny that there are instances of you in the
archives protesting against the use of srand(time(NULL)), the only
difference being that your buddy Heathfield wasn't involved
at those times.

Hilarious.

Indeed.

It's just like the Bush Administration - it's all personality-driven.
 
B

Beej Jorgensen

blargg said:
Someone having a program fail because it's non-portable

I don't think this particular program will fail because of
srand(time(NULL)), but he can let us know if it does and then I'll owe
you a pint. :)

-Beej
 
L

lawrence.jones

James Dow Allen said:
Why not
find the hypothetical library that makes time() a
float and stamp it out:

It's not hypothetical: SAS/C for the IBM mainframe implements time_t as
double. (The system time-of-day clock has subsecond resolution, so it
makes some sense to expose that to C programs.)
 
P

Phil Carmody

Han has said that his intention is to disrupt c.l.c, and has,
like the thirteen-year-old that his mental age is, threatened
to continue doing so.
if it walks like a duck...


I suggest the original poster reads some back-posts and make his
own mind up.

But not too many, the killfile is the best place for such things.

Phil
 
K

Kenny McCormack

Han has said that his intention is to disrupt c.l.c, and has,
like the thirteen-year-old that his mental age is, threatened
to continue doing so.

1) Wrong. He never said that. Remember, in order to qualify, the
sentence must begin with "My objective is ..."

2) The claim above was Han said his objective was to "destroy" CLC. The
claim of "disrupt" was about yours truly. You guys need to keep
your stories straight.

(Just keepin' in the Aspergers spirit of the place, doncha know...?)
 
B

Ben Bacarisse

Keith Thompson said:
Why not
find the hypothetical library that makes time() a
float and stamp it out:

It's not hypothetical: SAS/C for the IBM mainframe implements time_t as
double. (The system time-of-day clock has subsecond resolution, so it
makes some sense to expose that to C programs.)
[...]
One obvious disadvantage is that the resolution varies over time. For
times sufficiently close to the epoch, you can distinguish between one
yottasecond and the next. By now, the resolution (given FLT_RADIX ==
16 and DBL_MANT_DIG == 14, thus 56 bits of precision) is around 3.7
nanoseconds, and it will remain there for some time. If that's finer
than the resolution of the system time-of-day clock, I suppose that's
not a real problem. But I still think it would have been better to
use a large integer representing, say, a number of nanoseconds.

How is that much different than say using a nanosecond timebase and
dividing that value by 1e-9? Either way, once the time value gets
sufficiently large, you get less and less than nanosecond
resolution.

Yes, but you are not forced to divide by 1e9. For example if you
subtract two times you get nanosecond resolution for years to come. A
floating time (or two integer nansecond times divided by 1e9) slowly
loses resolution as time goes by.

And if you do need to divide, having the integer version lets you
decide how to do that. You could use a wider floating type, or an
arbitrary precision maths library. A constant resolution integer time
is simply a better design.
 
R

R J C

CBFalconer scribbled:
You didn't quote anything Han wrote. However, be advised he is an
admitted troll, with the stated objective of destroying
comp.lang.c. You are better off ignoring him.

Yes, but as in this thread, he is an admitted troll (for those who weren't
around, he used to have "Master Troll" placed after his name) who has a
good track record for being right. I would suggest the OP do as I said
and ignore only his childish rants and insults. If it weren't for Han
from China, the OP would have gone away using non-portable code. That
can't be denied.

FWIW, I find that people behave in ways for which they're rewarded, even
if that reward is only a great deal of negative attention. Think about
that. If his negative behavior were actually completely ignored,
something that has yet to occur on this newsgroup (the irony being that
those who repeatedly pop up and suggest ignoring Han being the ones least
able to do it themselves), I think there'd be less of it. That's why I
gave attention to only his positive contribution in this thread. That was
quickly derailed by those with their own form of disruption, who don't
seem to realize that they're only compounding the problem and unwittingly
helping Han with newsgroup disruption. I would go further and say that
they're the victims of highly clever manipulation, a very successful
attempt to drag them down to the same level of unwarranted attacks and
mudslinging.

An outside observer would look at this thread and see two parties
attacking each other. One of those parties has the force of technical
accuracy behind him, the only distinguishing feature between the two
mudslinging parties. I don't for a minute believe that this kind of
situation wasn't deliberately thought out and carefully engineered on this
newsgroup. Given a choice between a mudslinger who's right and a mature
person who's wrong but who quietly ignores or even gracefully accepts the
posts of the mudslinger, the mudslinger would quickly lose fans. But
given the choice between a mudslinger who's right and a mudslinger who's
wrong, most people will side with the mudslinger who's right.

Furthermore, Han is affable and amiable with querents on this newsgroup, a
sharp contrast to the often rude and smug replies from the other party.
I'm not stupid enough to believe that Han is naturally affable and
amiable---it's all part of the successful engineering in which he has
blurred differences to his advantage. His stated objective has been
achieved, and some people here have only themselves and their personality
flaws to blame.

Rob
 
K

Keith Thompson

R J C said:
Furthermore, Han is affable and amiable with querents on this
newsgroup, a sharp contrast to the often rude and smug replies from
the other party. I'm not stupid enough to believe that Han is
naturally affable and amiable---it's all part of the successful
engineering in which he has blurred differences to his advantage.
His stated objective has been achieved, and some people here have
only themselves and their personality flaws to blame.

So Han is successful in his deliberate attempts to disrupt this
newsgroup, and it's *our* fault?

Seriously?

Here's the problem: Just ignoring him doesn't work. We get people
showing up here who don't know the history, and, through no fault of
their own, they're susceptible to HfC's trolling. And don't forget,
HfC doesn't *just* post a mixture of insults and technically accurate
material; he also posts deliberately misleading material.

I ignore him as much as I feel I can, but sometimes I have to warn
people.
 
K

Kenny McCormack

So Han is successful in his deliberate attempts to disrupt this
newsgroup, and it's *our* fault?

Yes. Ever hear the expression "No one can abuse you without your
permission". Truer word were never spoken, nor were they ever so
appropriate as here, in the context of this NG.
Here's the problem: Just ignoring him doesn't work. We get people
showing up here who don't know the history, and, through no fault of
their own, they're susceptible to HfC's trolling. And don't forget,
HfC doesn't *just* post a mixture of insults and technically accurate
material; he also posts deliberately misleading material.

It's always couched in terms of protecting the innocents, isn't it?
I ignore him as much as I feel I can, but sometimes I have to warn
people.

Another spills drink moment. You have him killfiled. You never read
anything he writes. How can you possibly be aware of any of it?
 
R

R J C

Keith Thompson scribbled:
So Han is successful in his deliberate attempts to disrupt this
newsgroup, and it's *our* fault?

Seriously?


Here's the problem: Just ignoring him doesn't work. We get people
showing up here who don't know the history, and, through no fault of
their own, they're susceptible to HfC's trolling. And don't forget,
HfC doesn't *just* post a mixture of insults and technically accurate
material; he also posts deliberately misleading material.

I think even Han has realized that posting gag answers or deliberately
misleading material won't work as a means of trolling this newsgroup.
There are too many people who will blunt the effect of such answers. I
haven't seen such answers for a very long time.

The sadly humorous state of affairs is that his trolling these days
largely consists of being affable and amiable to all querents (including
those who post off-topic questions or homework questions), pointing out
"double standards" that are unfortunately clear and hard to deny and have
an appeal to the common poster, and offering answers and corrections that
are, if anything, /too/ accurate (in the sense of being technically
correct by the letter of the ISO standard but of little practical merit),
all the while tossing in some unwarranted insults of his pet targets. I
can't think of any other newsgroup where someone could enjoy themselves so
much by trolling in that manner. Think about that.
I ignore him as much as I feel I can, but sometimes I have to warn
people.

It's painful watching a knowledgeable and valuable contributor like you
fall into that trap, Keith. I propose that warnings be issued only when
there is a clear sign of an attempt to provide deliberately misleading
material. Otherwise, the trap that you, CB, &c. fall into is looking more
than a bit clownish when he's actually providing helpful material, as in
this thread.

It's not your fault he may be trying to disrupt this newsgroup, but you
can take measures to make the attempts far less less successful than they
currently are.

Rob
 
L

lawrence.jones

Keith Thompson said:
One obvious disadvantage is that the resolution varies over time.

Some would consider that an advantage -- you can represent reasonably
contemporary times with a great deal of precision whilst still being
able to represent times in the far distant future or past (albeit with
much less precision) without requiring a large amount of storage.
But I still think it would have been better to
use a large integer representing, say, a number of nanoseconds.

As I recall, the original SAS/C implementation didn't have integers
larger than 32 bits.
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top