N
Nick Keighley
I argued (possibly without enough thought!) that atoi()
was less undesirable than gets().
I suppose I was thinking that the "likely" undefined behaviour
was less draconian for atoi() than gets(). I never use gets() and
I rarely use atoi(). In future I will be using atoi() even less!
yes, but we tend to have a mental model of what we can
reasonably expect an implementation to do. Most atoi()s return
zero if you hand them rubbish (I was quite surprised to find this
wasn't what the standard said (I have code that relies on this...)).
I hadn't considered what overflow was likely to do. :-(
gets() on the other hand with the obvious implementation is just
going to stomp all over memory. And that can't possibly be good.
I'm not sure I see the distinction between "Standard" behaviour and
"everyday" behaviour.
there's behaviour in what a program does and behaviour as in a range
of permitted actual behaviours some future execution of a program may
have. I suppose the standard is defining behaviour in the "future
imperfect" sense.
I think the standard is constaining the possible behaviours of the
program.
I'd say that was exactly what it meant!
sounds the same to me...
again it seems to me a distinction without a difference
yes but the standard is reasoning about an abstract machine.
The abstract machine is immune to cosmic rays.
The standard is saying
"if, and only if, the implementation's actual external appearance or
action corresponds with the abstract machine's external appearance
or
action does this standard apply."
Possibly the actual machine's behviour has to be a subset
of the AM's set of behaviours.
I'm beginning to see what you may mean. But if we start talking
about implmentations and real world hardware I think we might
be outside the standards domain of discourse.
--
Nick Keighley
"Programs must be written for people to read, and only
incidentally for machines to execute."
- Abelson & Sussman,
Structure and Interpretation of Computer Programs
was less undesirable than gets().
I suppose I was thinking that the "likely" undefined behaviour
was less draconian for atoi() than gets(). I never use gets() and
I rarely use atoi(). In future I will be using atoi() even less!
yes, but we tend to have a mental model of what we can
reasonably expect an implementation to do. Most atoi()s return
zero if you hand them rubbish (I was quite surprised to find this
wasn't what the standard said (I have code that relies on this...)).
I hadn't considered what overflow was likely to do. :-(
gets() on the other hand with the obvious implementation is just
going to stomp all over memory. And that can't possibly be good.
I'm not sure I see the distinction between "Standard" behaviour and
"everyday" behaviour.
there's behaviour in what a program does and behaviour as in a range
of permitted actual behaviours some future execution of a program may
have. I suppose the standard is defining behaviour in the "future
imperfect" sense.
I think the standard is constaining the possible behaviours of the
program.
Consider a statement like "if XYZ, the behavior is undefined."
This doesn't mean that what the program does is undefined;
I'd say that was exactly what it meant!
it
means what the program is allowed to do by the Standard is
undefined.
sounds the same to me...
Now consider a statement like, "if I give my program an input
file of /dev/null, its bevahior is a little screwy." This
doesn't mean the program is allowed to be a little screwy, it
means what it actually does is a little screwy.
again it seems to me a distinction without a difference
Another example: {unsigned u = 0; u = u+1; return u;} This
program fragment has "well-defined" behavior. But if we run the
program, and the memory for u gets hit by a cosmic ray, what the
program actually does may be different from what the Standard
requires it to do.
yes but the standard is reasoning about an abstract machine.
The abstract machine is immune to cosmic rays.
The standard is saying
"if, and only if, the implementation's actual external appearance or
action corresponds with the abstract machine's external appearance
or
action does this standard apply."
Possibly the actual machine's behviour has to be a subset
of the AM's set of behaviours.
Its behavior(1) is defined by the Standard,
but its behavior(2) is affected by cosmic rays (which are not
part of the Standard). The terms behavior(1) and behavior(2)
clearly can't mean the same thing.
Do you see the difference I'm trying to illuminate?
No problem. These ideas are difficult to communicate.
I'm beginning to see what you may mean. But if we start talking
about implmentations and real world hardware I think we might
be outside the standards domain of discourse.
--
Nick Keighley
"Programs must be written for people to read, and only
incidentally for machines to execute."
- Abelson & Sussman,
Structure and Interpretation of Computer Programs