Did you know?

  • Thread starter Vijay Kumar R Zanvar
  • Start date
N

Neil Cerutti

even better, use memcmp() for all equality comparisons of
integers, and have all magic numbers as constant variables.

Heh.

In C99, you can even write your own store: an inline function.
 
R

Richard Heathfield

Jeremy said:
I don't want to belabour the point,

Neither do I. Ultimately, it's a style thing, and no style argument ever got
settled here.
but the former still sounds
unnatural to me.

It does to me, too, in English. I tend to think of C and English as separate
languages, though. :)
It denotes value equality, yes, but a variable is not the same /kind/
of thing as a literal, which is why most people do not find "if (x == 1)"
and "if (1 == x)" equally readable, whichever they prefer.

(Given that neither of us is going to persuade the other...) How do you feel
about these code fragments?

if(SUCCESS == rc)

if(Success == rc)

if(success == rc)

I'm just curious. I ***promise*** I won't argue with your reply (because
it's a style thing, so I'm taking it as read that we've agreed to differ).
 
A

Arthur J. O'Dwyer

Neither do I. Ultimately, it's a style thing, and no style argument ever got
settled here.

True dat.
So I'll try to avoid this thread, but since I've been
belaboring the point, too, here's some feedback on
the below.
(Given that neither of us is going to persuade the other...) How
do you feel about these code fragments?

First off, all of them should have whitespace between the keyword
'if' and the open parenthesis '('. 'if', like 'sizeof' and 'return',
is not a function. :)
if(SUCCESS == rc)

Looks like SUCCESS is a macro. Which has a constant value.
So 'rc' must be a variable, probably a return code. So this
comparison means "if the return code is SUCCESS, do x."
It's backwards [:)], but readable at a glance.
if(Success == rc)

Hmm. I don't write code that looks like that. My first
impression would be that 'Success' is a global variable,
or more likely a member of an enumeration. But I'd have
to check to make sure, and I'd look first at the top of
the current source file.
if(success == rc)

Ambiguous out of context. 'success' is a plausible name
for a boolean variable (or an 'int' masquerading as a
boolean). It's only by looking above and below this line
that I can tell that 'rc', being briefer, must be the
variable name, and 'success', being non-orthogonal to
'rc' (i.e., not named 'sc' or 'rd' or something similar)
must really be a constant.

Perhaps I'd write this in the dubious context


rc = vsscanf(input_buffer, user_defined_fmt, ap);
success = user_defined_number_of_values + 1;
if (success == rc)
...

but again, I'd be more likely to think, "Is RC successful?"
than "Is 'success' equal to RC?" and thus write the condition
the other way.

I'm just curious. I ***promise*** I won't argue with your reply (because
it's a style thing, so I'm taking it as read that we've agreed to differ).


-Arthur
 
C

CBFalconer

Arthur J. O'Dwyer said:
.... snip ...


First off, all of them should have whitespace between the keyword
'if' and the open parenthesis '('. 'if', like 'sizeof' and
'return', is not a function. :)

New style war. You are not going to persuade him, I have tried
:)
 
R

Richard Heathfield

Arthur said:
First off, all of them should have whitespace between the keyword
'if' and the open parenthesis '('. 'if', like 'sizeof' and 'return',
is not a function. :)

You're not Jeremy, so I haven't promised not to argue with you. :)

Seriously, whitespace is /also/ a style issue. In your eyes, the additional
whitespace between if and ( is desirable. In my eyes, it isn't. So - FOR
YOU - it /should/ be there (or, perhaps, /must/ be there?). For me, it must
not.

<very interesting comments snipped - I will *not* get deeply involved in a
style discussion; I will *not* get deeply involved in a style discussion; I
will *not* get deeply involved in a style discussion; I will *not* get
deeply involved in a style discussion; I will *not* get deeply involved in
a style discussion; I will *not* get deeply involved in a style discussion;
I will *not* get deeply involved in a style discussion...>
 
J

Joona I Palaste

Not really. The = sign in mathematics just means something slightly
different than it does in C. If you want Pascal or BASIC, you know
where to find them. (The mathematical = relation is equivalent to the
C == operator, and indeed in C (i == i+1) has no solution for
unsigned integral i.)

Invalid point. BASIC uses = for *both* assignment and equality. The
difference is whether it's used in a (possibly implicit) LET command or
in an expression.
Pascal, OTOH, is free of such confusion and uses := for assignment.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
 

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

Forum statistics

Threads
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top