Re: Fw: [Dev-C++] help files and Operator Precedence
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-12-11 17:39:53
|
Borland have always shipped excellent help files - or at least used to,
since I haven't used any recent Borland compilers.
Of course a good online help should include operator precedence, just as
it should contain the runtime library reference, or at least a direct link
to a separately installed GNU documentation or similar.
What I meant by operator precedence being basic programming skill is that
I don't think that they are something that should require massive amounts
of googling for. For beginners they should be max two seconds away, and
for experienced programmers they should be "hard-coded" in memory. Any
person who works full-time programming C or C++ should be able to remember
the rules even if waked up in the middle of the night. That is one of the
cornerstones for writing bug-free code.
Most programming languages have very similar operator precedence rules,
which isn't so strange since most of the rules have been created as a
result of a bit of logic thinking and are based on non-programming rules
from the mathematics world.
About using massive amounts of parentheses in the source code, some
programmers feels that operator precedence is black magic and if they
don't clearly show the execution order neither the programmer self - or
any other programmer - will be able to later look at an expression and
deduce what it does.
It's fine by me if people want to be very clear when doing bit or shift
operators or similar, but I get a bit of an headache when
multiplication/division needs parentheses to convice the world that they
should be evaluated before addition/subtraction. The expressions below
have the big problem that it starts with four lpar making it very hard to
immediately keep track of the corresponding rpar.
One other thing I have noticed is that some programmers somehow think that
operator precedence isn't 100% fixed, but might vary between compilers,
and just because it works on "their" compiler they still feel a need for
parentheses to make sure the code is portable. I don't know if this has
something to do with parameter passing, where the compiler is free to
decide which order the parameters should be evaluated. What I mean is aa
construct like:
int i = 0;
printf("%d %d %d\n",i++,i++,i++);
where all bets are off about the resulting output. The funny thing with
the above code is of course that parentheses can't be used to solve the
problem anyway, so there really are no similarities with normal operator
precedence.
/Per W
On Sun, 12 Dec 2004, Eric wrote:
> O bye the way ......
>
> the fact that someone wrote
> x = ((((mm-1)*31)+dd)-1)%8;
> y = ((((mm-1)*31)+dd)-1)/8;
>
> is a clear indication that people that do "programming micro-controller with C" more than I do and I was
> able to pick up the correction show that not everyone is up to speed with operator precedence.
>
>
> A very good reason why this should included in upgrade version of [Dev-C++] help notes after all
> Borlands have done it and they are not a "fly by night - half measure company"
>
>
> >From Eric
>
>
>
> ----- Original Message -----
> From: "Eric" <eri...@cl...>
> To: <dev...@li...>
> Sent: Sunday, December 12, 2004 3:48 AM
> Subject: Re: [Dev-C++] help files and Operator Precedence
>
>
> OK
>
> It is just that I don't do C++ full time nor do I programming micro-controller with C full time, A
> employment option in ether direction would be great !!! :)
>
> This is why I have kept the C++ notes in folder and refer to them and upgrade them from time to time as
> needed,
>
> The only reason why I made a posting is so I could find (and others as well) the operator precedence
> order in the help file if I need to and don't have access to my notes, I am sure you Per Westermark would
> not need them but other people might find it useful and stop them posting to this group on a trivial
> problem using operator precedence.
>
> After all I did see a "Hello world" example in the help files briefly while looking for something else.
>
> Also I do realize that operator precedence (and did while I was at school) that the operator precedence
> does not change between local and global variables, it was (it the time) a reminder that in a function a
> global variable would be ignored if there was a local variable defined in that function.
>
> >From Eric
>
>
>
>
>
>
>
>
> ----- Original Message -----
> From: "Per Westermark" <pw...@ia...>
> To: "Eric" <eri...@cl...>
> Cc: <dev...@li...>
> Sent: Sunday, December 12, 2004 3:27 AM
> Subject: Re: [Dev-C++] help files and Operator Precedence
>
>
> Knowing thee precendence rules are part of basic programming skills.
>
> Anyway, there are _no_ precedence difference between auto and global
> variables when evaluating an expression.
>
> There is, of course, a difference in the time when the
> constructors/destructors will be run for variables declared global, auto
> or dyanmically allocated.
>
> /Wer W
>
> On Sun, 12 Dec 2004, Eric wrote:
>
> > Hi I belong to a micro-controller group,
> >
> >
> > someone in the group presented a formula (which might not be the problem to their question)
> > x = ((((mm-1)*31)+dd)-1)%8;
> > y = ((((mm-1)*31)+dd)-1)/8;
> >
> >
> > I told them it could be written as
> > x = ((mm-1)*31+dd-1)%8;
> > y = ((mm-1)*31+dd-1)/8;
> >
> >
> > if they look on the "Operator Precedence chart"
> >
> > it took me a while to remember I had printed off the Operator Precedence chart from the Borland help
> > files, for my own C++ notes (while I was at C++, school)
> >
> > While you can find the Operator Precedence chart on Internet with the help of Google, a couple of web
> > sites I have seen does not tell that most Operator Precedence level (16 in all) go from left to right,
> > but there are three that go from right to left, level 2, 13 and 15.
> >
> >
> > Hand written on the bottom of the page is a reminder local variables take precedence over global
> > variables (I was at school at the time when I wrote the notes, OK)
> >
> >
> >
> > The Aim of this posting is a suggestion this could included in the (dev-C++) help files on future
> > upgrades unless I am using a old version you can correct me and I would be grateful.
> >
> >
> > >From Eric Richards
> >
> >
> >
> >
> >
> >
> >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.809 / Virus Database: 551 - Release Date: 09-Dec-04
> >
> >
> >
> > -------------------------------------------------------
> > SF email is sponsored by - The IT Product Guide
> > Read honest & candid reviews on hundreds of IT Products from real users.
> > Discover which products truly live up to the hype. Start reading now.
> > http://productguide.itmanagersjournal.com/
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.809 / Virus Database: 551 - Release Date: 09-Dec-04
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|