need help..

C

CBFalconer

Christopher said:
Yes, that's very convenient, although my implementation at least will
generate a warning. I don't know if gcc does, and I wonder whether
lint and friends will complain.

gcc will make muttering noises about using extra parentheses, after
which it will quieten down. The real point is that it is easy to
see what preconditions (and in what order) are needed to attain
singing birds.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
 
D

dot

You can use your macros if you like, but I guarantee they'll make it
more difficult for anyone else to read or maintain your code.

See that's just is... *nobody* will ever see or maintain my code.

Believe me... it just won't happen.
 
D

dot

The problem is that you would make the above valid code illegal.

How exactly does using a couple of aliases the cut down on errors make that
code illegal?

If I were writing what you have above I would write...

if (err = setupphase(1))
bitchabout(1, err);
else if (err = setupphase(2))
bitchabout(2, err);
else if (err = setupphase(3))
bitchabout(3, err);
else { ...

So tell me again... what exactly is the problem?
 
D

dot

Reminds me of the poster a decade back or so who posted macros that made C
look "pascal-like". Macros of the sort of
#define BEGIN {
#define END }

Just as useless, too.

Given that in my learning phase this cut the number of errors I was making
to less than a third... not useless.

Lately I don't use them all that much ... you see I'm learning... eventually
I'll most likely abandon them altogether.
 
A

A. Sinan Unur

If I were writing what you have above I would write...

if (err = setupphase(1))
bitchabout(1, err);
else if (err = setupphase(2))
bitchabout(2, err);
else if (err = setupphase(3))
bitchabout(3, err);
else { ...

So tell me again... what exactly is the problem?

You snipped the part where you proposed that assignment within if( ... )
be made a syntax error. That is, if your own proposal is adopted, you
would not be able to write what you just wrote. Instead, you would have
to write

err = setupphase(1);
if(err)
bitchabout(1, err);

etc.

Sinan
 
P

pete

See that's just is... *nobody* will ever see or maintain my code.

Believe me... it just won't happen.

In that case, your style of coding is bad.

A good style, is one which makes the code easy to maintain
by someone who has never seen the code before.
 
D

dot

A good style, is one which makes the code easy to maintain
by someone who has never seen the code before.

But, as I keep trying to get through your noggin... Nobody's ever going to
see my source code... I am the only person who will ever have to read or
revise anything I've written.

Really... I work alone, on a contract basis. It is *understood*
contractually that I do not share or divulge source code to *anyone*. I
plan taking my secrets to the grave with me.

Style, portability and standards simply aren't issues in the work I do.
Because of the nature of that work, I prefer a language that is as tightly
integrated with (read "specific to") an operating system as I can get. I
deliberately chose a version of C that is platform specific, with no cross
compilers and no attempt at generalization... because I need that kind of
closeness to do what I do.

Why this bothers people here so much is beyond me.
 
K

Keith Thompson

How exactly does using a couple of aliases the cut down on errors make that
code illegal?

If I were writing what you have above I would write...

if (err = setupphase(1))
bitchabout(1, err);
else if (err = setupphase(2))
bitchabout(2, err);
else if (err = setupphase(3))
bitchabout(3, err);
else { ...

So tell me again... what exactly is the problem?

I have no idea. Your code is identical to CBFalconer's code except
that you split the lines. You've objected to using an assignment as a
condition; now you post code that does exactly that.

I have no problem with the code you just posted; it just seems to
contradict what you've been saying.
 
K

Keith Thompson

But, as I keep trying to get through your noggin... Nobody's ever going to
see my source code... I am the only person who will ever have to read or
revise anything I've written.

Then you're in an unusual position. If it works for you, and if
nobody else will ever have to deal with it, there's not much reason
anybody else should care.

I find that good style leads to more reliable code. I also try to
keep in mind that I may have to maintain the code myself years from
now. I don't like to think of my future self asking what the hell I
was thinking when I wrote this stuff (as I've done sometimes when
reading my own old code).
Really... I work alone, on a contract basis. It is *understood*
contractually that I do not share or divulge source code to *anyone*. I
plan taking my secrets to the grave with me.

I probably wouldn't work with someone on those terms.)
but that's between you and whoever you work with.

[snip]
Why this bothers people here so much is beyond me.

Because you told us about it. If you keep it to yourself, nobody will
know or care. If you choose to share it, people will offer their
opinions. If you didn't want our opinions on your coding style, I'm
at a loss to understand why you posted about it.
 
C

CBFalconer

Keith said:
I have no idea. Your code is identical to CBFalconer's code except
that you split the lines. You've objected to using an assignment
as a condition; now you post code that does exactly that.

Except in the process he has lost the clarity, in that it no longer
as clearly shows the prerequiristes satisfied to allow the action.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
 
D

dot

I have no idea. Your code is identical to CBFalconer's code except
that you split the lines.

My point exactly. In that case I would probably do pretty much as he did.
You've objected to using an assignment as a
condition; now you post code that does exactly that.

Mo I have not. You misunderstand.

I grumbled about using the same symbols for differing purposes. I get why
it was done... they ran out of punctuation. But the problem is that it was,
I think, poorly thought out... It would have been FAR clearer and a lot
easier to get one's head around if they'd played by some set of rules. Like
I said, single characters are assignments and double characters are tests.
It would sit much more clearly in a person's mind than the "Except for this,
that is true" setup currently in use.

I have no problem with the code you just posted; it just seems to
contradict what you've been saying.

I can see where you might think that... but look more closely at what I've
been saying. I've been trying to make a point about consistent rules within
the language.

Assignment ... =, &, |, <, >, %
Testing ... ==, &&, ||, <<, >>, %%

(or visa versa)

Ok I get that it's not that way and I've no problem working with it as it
is. I do, afterall, like C just fine. I'm simply pointing out how
confusing it is for someone who's just learning. If there was a rule, it
would help.

My point that allowing assignments inside a comparison should flag a syntax
error was that, were it so, it's likely 4/5ths of the mistakes I made while
learning would have been caught by the compiler. And there are, afteral,
ways around using assignments inside conditionals.

The original examples (for example) could easily be broken into two
statements with the same result...

err = function()
if (err)
...

So it's not like it would have crippled programmers to do it.

But... they didn't do it that way, it is what it is and this whole
discussion is getting a little silly.
 
D

dot

Then you're in an unusual position. If it works for you, and if
nobody else will ever have to deal with it, there's not much reason
anybody else should care.

My point exactly. I work on my own, without schedules, on those silly
little projects the big programming houses won't touch. It's not going to
make me rich, but it does provide the basics. I could probably double my
income by taking a conventional job... but then I've got deadlines,
standards, rules, hours, bosses, commuting and all that crap to deal with.

I find that good style leads to more reliable code.

As do I. I don't write sloppy code. Even if nobody else ever sees it, I
still have to read it later. I'm sure _my_ style would look very strange to
you... but it makes perfect sense to me.

I probably wouldn't work with someone on those terms.)
but that's between you and whoever you work with.

Ok, you're some small mom and pop operation and you need a custom utility
to, say, purge files older than a given date. You go to "the big code
company" and get a quote that would put you into bankruptcy... next you come
to me, you let me do my thing, and you get it at a fraction of the price.

If you think about it, it's not even competition... I just get the stuff
nobody else wants.

Because you told us about it. If you keep it to yourself, nobody will
know or care. If you choose to share it, people will offer their
opinions. If you didn't want our opinions on your coding style, I'm
at a loss to understand why you posted about it.

Ever heard of casual conversation?
 
A

A. Sinan Unur

look more closely at what I've been saying. I've been trying to make
a point about consistent rules within the language.

Assignment ... =, &, |, <, >, %
Testing ... ==, &&, ||, <<, >>, %%

Hmmm ... where is the assignment in

if(a < c) { ... }
... this whole discussion is getting a little silly.

Absolutely.

Sinan
 
D

dot

(e-mail address removed) wrote in


Hmmm ... where is the assignment in

Not IS ... should have been.

I didn't say it IS that way, I said it would be better if it was.

I've also repeatedly pointed out that it isn't, and there's not much can be
done about it at this late stage of the game.

Gees.
 
M

Mark McIntyre

If the compiler can detect it sufficiently to warn, it can hand out an
error, stop compilation and force you to fix it.

point is, it might be able to warn you, but its a perfectly legal
construct, and one that many people use deliberately.
Frankly, it would have made more sense to have the testing done on a single
=, & or | marks and use the doubles for assignment along with >> and <<
which are used for bit shifts.

If you have a time machine, pop back thirty odd years and mention that
to the designers of BCPL and B. Otherwise, you'll need to discuss it
in the context of a new language.
 
M

Mark McIntyre

See that's just is... *nobody* will ever see or maintain my code.

And with luck, nobody will ever see your backside. Thats no reason to
leave it all covered in sh...
Believe me... it just won't happen.

so what? Is that a good reason to learn bad habits?
 
K

Keith Thompson

Sorry... I've done no such thing. Discussion is not advocacy.

Upthread:

] >3) Quality compilers warn about the ``if (foo = 0)'' construct.
]
] It should be a syntax error.

I'm not sure of the attributions, but the "It should be a syntax
error." was yours. Looks like advocacy to me.

It really doesn't matter to me whether you were advocating anything or
not. All anybody has been doing here is discussing things. That's
what this newsgroup is for.
 
D

dot

I'm not sure of the attributions, but the "It should be a syntax
error." was yours. Looks like advocacy to me.

It really doesn't matter to me whether you were advocating anything or
not. All anybody has been doing here is discussing things. That's
what this newsgroup is for.

Well, except for you and Falconer who seem mostly concerned with litigating
a case against every posting that doesn't fit your ideal guidelines.

Really... It's effing amazing to watch the self-appointed group leaders on
Usenet litigate their way to dominance and control, mostly by nitpicking
posts and defaming participants.

I came here to discuss C ... so far I've been ruled off topic, ordered out
of the group, lectured about etiquette and now subjected to micro-analysis
of my ever word.

What's next? Bamboo under my toenails?
 

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,161
Messages
2,570,892
Members
47,429
Latest member
JacelynKit

Latest Threads

Top