Re: simple increment operator question.
From: The Real OS/2 Guy (os2guy_at_pc-rosenau.de)
Date: 12/23/03
- Next message: osmium: "Re: checking an array."
- Previous message: Mike Hewson: "Re: how to simplify many OR in if statement?"
- In reply to: Jeff Schwab: "Re: simple increment operator question."
- Next in thread: Jeff Schwab: "Re: simple increment operator question."
- Reply: Jeff Schwab: "Re: simple increment operator question."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 23 Dec 2003 12:34:41 +0000 (UTC)
On Tue, 23 Dec 2003 08:04:42 UTC, Jeff Schwab <jeffplus@comcast.net>
wrote:
>
> I hope we can agree to disagree. This thread has gotten nasty in a
> hurry. :(
>
> Here are the suggestions you didn't like from my earlier post:
>
> 1. Avoid the post-increment operator, since it can be slow in C++.
>
> 2. Put the increment on a separate line, if unsure of the order of the
> increment's side-effects.
>
> 3. It might help to initialize an indexing variable to -1, then use
> pre-increment instead of post-increment.
>
> 4. Don't be afraid to look at the assembly code.
>
>
> Here are a few thoughts on these items.
>
> 1. I know from experience that this is good advice. I don't know
> whether the OP is using C or C++. In C, post-increment is fine. In
> C++, it is often inefficient. I was *not* suggesting that any given
> chip has a "post-increment" instruction that is somehow bad.
Changing the algorithm that uses it would be more efficient.
> 2. When unsure of the exact order of operations, it can be very helpful
> to separate a statement into multiple lines. This, too, I know from
> experience.
Learning how to use it brings more. Avoiding anything ends only up in
unability to write programs.
> 3. Chris was good enough to point out that I am mistaken about array
> indices, and that they are of an unsigned type. However, I would also
> point out that the indexing variable's name *does* imply that it is an
> int, so a value of -1 is fine. Also, since pre-increment would be used
> in this case, the array would never actually be indexed by a negative
> value. Still, I have at least learned something from this thread, so
> I'm grateful. :) Btw, initializing indexing variables to -1 is not an
> uncommon practice.
It is irritatiing anyway.
> 4. To say that it is bad for someone learning C or C++ to see the
> assembly code is... Well, I don't know a word for it. Are you worried
> that the OP will become obsessed with assembly, trying to write C code
> to generate particular instructions? Well, what if he does? That will
> make him a much better programmer than most.
No, it wouldn't. Avoiding some construncts because on lack of
understunding but requireing to learn assembly makes an foul. Learn
how an programming language works and don't try to learn another
language to get a bit feeling of the ordinate one.
Even when you aree an expert in one assembly language - it ould help
you to understund how the compiler works - even on a processer where
this assembly is common - there are often highly different assemblers
available - working differently, using different syntax. It will
confuse at least. I'm experienced in 10 different assebly dialects -
but none of them helps to get the best possible C or C++ code to run
on all 9 different processors even optimal - it doesn't help anyway to
write compatible C. For that matter it is essential to know how C (or
even C++) works - not what syntax an particular assembly owns.
> As to your more recent beefs, you feel that I think I86 [sic] is the
> only architecture. Do you think I'm sitting at an x86 box right now?
The header of your artikle says that.
> Hmmm... I've programmed a number of architectures, from
> microcontrollers to large servers, and I've found the instruction set
> for each of them interesting in its own way. Btw, my favorite is Sparc.
Doesn't matter. You have many to learn how to write robust, failsave,
compatible and optimal programs in C or C++.
> Also, you feel I have a problem with your poor English. I certainly
> don't have a problem with the fact that it is not your native language;
> I appreciate the fact that you are willing to have technical, often
> difficult discussions in a language you have not completely mastered.
> However, I do find it a bit surprising that you can't be bothered to run
> a spelling check on your posts. If a newbie posted code so wrong that
> it was obvious no attempt had been made to compile it, I would be
> equally bothered.
>
> So, that's my take on the whole thing. Bring on the flames, I guess.
>
There is no source to start flames. 20 years ago I was starting
programming in C with extensive assembly in mind, like you now - but
my epperience showed me quickly that thinking assembly and writing C
ends up very quickly in a desaster. So I ends up thinking REXX when I
have to write a REXX procedure, thinking C to write a C
program/function, thinking C++ whern C++ was the language to use. Yes
mixing up C and C++ is more errornous than mixing Cobol and Fortran
(both languages I had to use for longer time). For special hardware I
had learned programming in MUMPS, DICOL, RTL/2 and some other
languages. To get it right you've to learn to think in the language
you use.
In my carrer I was programming an OS in C (with the badest C compiler
thinkable) and thereafter maintenance it. By that I had rewritten the
floatingpoint emulator from scratch (because it was too memory
expensive) - getting as result an emulator that had used only 20% of
memory and increased the throughput around 300% of the old one while
it was 2 decimal digits more exactly than the floatingpoint processor
of the mashine and 4 as the old emulator. The designer of the
floatingpoint processor had rewritten his micro code to reach the same
exactness as the emulator - incresed its throughput on that way too.
Master the language you use perfectly helps more than knowing of
differnt languages.
-- Tschau/Bye Herbert Visit http://www.ecomstation.de the home of german eComStation
- Next message: osmium: "Re: checking an array."
- Previous message: Mike Hewson: "Re: how to simplify many OR in if statement?"
- In reply to: Jeff Schwab: "Re: simple increment operator question."
- Next in thread: Jeff Schwab: "Re: simple increment operator question."
- Reply: Jeff Schwab: "Re: simple increment operator question."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|