J
Jon
Does it really matter, considering that it is a void expression, that
assert is an expression instead of a statement?
assert is an expression instead of a statement?
Jon said:Does it really matter, considering that it is a void expression, that
assert is an expression instead of a statement?
Does it really matter, considering that it is a void expression, that
assert is an expression instead of a statement?
Ben said:Sure. A void expression can be incorporated into a larger
expression (e.g. with the comma operator). A statement cannot.
Seebs said:Probably, because you can use void expressions in at least a few
contexts in C:
x ? (assert(y), 1) : ...
More generally, the general rule in C is that things you could
possibly implement as expressions tend to be expressions.
(C doesn't
go as far in this as, say, Ruby or Lua, but it's still pretty
aggressive about it.)
Would you write code like that?
No.
I wouldn't. Have a better example?
And I'd go where to study that issue? Wikipedia? I do find it relevant
info, but, shouldn't it/that be knowledge?
Your stage. I'll review the draft paper/article if you want (as I will
ask many "dumb" questions).
Seebs said:Not really, but I don't need one -- it's that way because people
occasionally use assert() in larger expressions, possibly because an
assertion is only relevant in some contexts.
Read a bunch of C code and think about the "Spirit of C", pretty much;
I guess you could read the Rationale for the standard.
If you'll pay me for my time, I care what you think I should write.
Probably, because you can use void expressions in at least a few contexts
in C:
x ? (assert(y), 1) : ...
Jon said:I knew that. Do you have an example? I recently changed my assert macro
to be an expression and it DID clean things up nicely, but I think I
don't know the whole gist of the requirement and whether it's just a
corner case thing or a wildly-useful thing.
I've never put an assertion into a larger expression in practice.
Peter Nilsson said:Which kind of statement did you have in mind?
And what do
you gain by making it a statement?
Keith Thompson said:Presumably an expression statement, consisting of an expression followed
by a semicolon, such as:
assert(x == 42);
Convenience. (A related question would be what you would gain by
defining assert() so that it's only usable in a statement context;
the answer, as far as I can tell, is nothing.)
Keith Thompson said:Presumably an expression statement, consisting of an
expression followed by a semicolon, such as:
assert(x == 42);
Convenience.
(A related question would be what you would gain by
defining assert() so that it's only usable in a
statement context; the answer, as far as I can tell,
is nothing.)
I've never put an assertion into a larger expression in practice.
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.