B
boa sema
Richard said:Serve Laurijssen said:
Right; as I have said dozens of times in this newsgroup, assert is for
validating code, not data.
assert() is for validating code & data, but not input data.
Boa
Richard said:Serve Laurijssen said:
Right; as I have said dozens of times in this newsgroup, assert is for
validating code, not data.
assert() is for validating code & data, but not input data.
How about function arguments?Richard said:boa sema said:
What kind of data did you have in mind, other than input data?
How about function arguments?
One may of course argue that the calling *code* is broken if the data is
broken.
Serve Laurijssen said:well, using assert for things that can happen in production code too is also
not correct
Richard Tobin said:If you had said "... in correct production code ...", I would have
agreed. But I don't see any point removing assert()s from production
code (unless they're expensive to compute), because even in production
code it's generally better to abort with a useful message if there
turns out to be a bug in the code. No doubt there are exceptions.
Serve Laurijssen said:Yes so it is allowed....but here we go already. standard this year standard
that year and all about stuff that doesnt make you a better C coder. Like
with the assert(p)
[/QUOTE]If you had said "... in correct production code ...", I would have
agreed. But I don't see any point removing assert()s from production
code (unless they're expensive to compute), because even in production
code it's generally better to abort with a useful message if there
turns out to be a bug in the code. No doubt there are exceptions.
Well assert is not the way to gio then. You can add an assert like debug
facility that can be turned on/off by the user
Serve Laurijssen said:Well assert is not the way to gio then. You can add an assert like debug
facility that can be turned on/off by the user
But I don't see any point removing assert()s from production
code (unless they're expensive to compute), because even in production
code it's generally better to abort with a useful message if there
turns out to be a bug in the code. No doubt there are exceptions.
Well assert is not the way to gio then. You can add an assert like debug
facility that can be turned on/off by the user
Richard Bos said:True, but neither do I want to present him with a cryptic, tenth-of-a-
second flash
of (to him) unintelligible console text and an immediate
return to his desktop.
So rather than assert(), my preference is for a
function which can put a quotable, repeatable error message on his
screen and keep it there until he's finished phoning me.
??? Why do your assert messages only last a tenth of a second?
Ah. I don't use one of those desktop thingies.
Assert error messages may be cryptic, but they come with a file and
line number. I don't see why they would not be repeatable.
Keith Thompson said:I don't understand your point. How does understanding what's defined
in the C90 and C99 standards not make you a better C coder?
Richard said:If you had said "... in correct production code ...", I would have
agreed. But I don't see any point removing assert()s from production
code (unless they're expensive to compute), because even in production
code it's generally better to abort with a useful message if there
turns out to be a bug in the code. No doubt there are exceptions.
-- Richard
Serve Laurijssen said:I'm talking about the assert and enum comma example. Knowing those rules
doesnt help one at all to become a better C coder.
Last month I appeared for an interview with EA sports and they asked
me this question.
How would you divide a number by 7 without using division operator ?
> To suceed in these interviews, I fear that you must not be so smart as
> to outsmart the person asking the questions. So I suspect the right
> answer might have been
>
> number *= 0.142857142857143; // divide by 7
>
> which indeed, in quite a few contexts, is an approriate answer.
Dik T. Winter said:Indeed, it gives the correct answer for all integers from 0 to
2147483647.
And probably down to -2147483648.
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.