Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #474279

Re: Microchip ICD4 ?

From David Brown <david.brown@hesbynett.no>
Newsgroups sci.electronics.design, comp.lang.forth
Subject Re: Microchip ICD4 ?
Date 2017-08-21 16:43 +0200
Organization A noiseless patient Spider
Message-ID <onerbe$a40$1@dont-email.me> (permalink)
References (6 earlier) <on6ie0$jd$1@dont-email.me> <5996d249.111613302@news.eternal-september.org> <87mv6won5c.fsf@nightsong.com> <2017Aug18.190621@mips.complang.tuwien.ac.at> <mOGlB.665617$lQ6.78056@fx29.am4>

Cross-posted to 2 groups.

Show all headers | View raw


On 18/08/17 20:59, Tom Gardner wrote:
> On 18/08/17 18:06, Anton Ertl wrote:
>> Paul Rubin <no.email@nospam.invalid> writes:
>>> stephen@mpeforth.com (Stephen Pelc) writes:
>>>> Where gcc (in particular) wins is in the huge amount
>>>> of time and money spent on the ARM and x86 versions
>>>
>>> The type system also helps with alias analysis,
>>
>> It doesn't.  What you mean is: By (often wrongly) assuming that C
>> programs don't access data through pointers of other types,
>> adversarial C compilers save themselves the trouble of trying to do
>> proper alias analysis.  But of course, the result is often wrong,
>> because the assumption is often wrong.
> 

You mean C compilers generate code that does not do what the programmer
expected, when the programmer does not know how to write C code properly?

A programming language - any programming language - is a contract
between the programmer and the compiler.  The programmer promises to
obey the rules of the language, and the compiler promises to give object
code that implements the source code.  If the C programmer accesses data
through pointers of other types, without taking proper measures (using
unions, memcpy, volatile, char* types, or implementation-specific
techniques), then he is breaking his side of the bargain.

I don't think type-based alias analysis actually helps very much in
optimisation, but on the other hand I don't see it as being a high risk
of mistakes.  Code that messes about accessing the same data as
different types is usually wrong anyway - and if you really /do/ want to
do it, there are perfectly good and efficient ways to do it correctly.

And if you want to write code that gets this wrong - such as the Linux
kernel - then compilers that implement strong optimisations typically
have options to control that behaviour.  gcc has "-fno-strict-aliasing".
 And since it does not do alias analysis unless you ask it for
optimisation, you can just add that in as an option along with "-O2" or
whatever optimisation options you pick.  (That's what the Linux kernel
does.)

> Too true :( Plus the programmer often lies.

Lie to your compiler, and it will bite you.  I have sympathy for people
who make mistakes in their coding - no programmer is perfect (not even
Forth programmers).  But I have little sympathy for people who knowingly
write bad code because they feel it /should/ work.

> 
> What /is/ the consequence of one compilation unit
> "casting away the constness" of something defined
> in another compilation unit?
> 

If you have an object originally defined as "const", and cast away that
constness, then try to write to the object - then you get undefined
behaviour.  The consequences are therefore unpredictable.

In C, if you use a "const" pointer, you are saying "I promise not to
change the thing pointed at, via this pointer".  No more, no less.  You
are not claiming you will /never/ change the object, just that you won't
do it with that pointer.

But if the object is originally defined with "const", then you /are/
promising that the object will never be changed.  (If it is "volatile
const", you are saying that something else might change it, but you
never will.)  The compiler can optimise on that assumption - it can use
the const value directly in code without creating an object in memory,
or it can put the object in read-only memory, or it can do both.

So if the original object is const and you cast away the constness
(which is allowed), and then try to write to it (reading is fine), you
are breaking your contract and anything can happen.  In particular, some
bits of code might read the new value, other bits might continue to use
the old value.  And the write itself can fail if the memory is protected
against writing in some way.

Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Microchip ICD4 ? Martin Riddle <martin_rid@verizon.net> - 2017-08-17 13:45 -0400
  Re: Microchip ICD4 ? DemonicTubes <tlackie@gmail.com> - 2017-08-17 12:17 -0700
    Re: Microchip ICD4 ? Martin Riddle <martin_rid@verizon.net> - 2017-08-17 15:32 -0400
    Re: Microchip ICD4 ? speff <spehro@gmail.com> - 2017-08-17 19:02 -0700
  Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 15:52 -0400
    Re: Microchip ICD4 ? piglet <erichpwagner@hotmail.com> - 2017-08-17 21:23 +0100
      Re: Microchip ICD4 ? boB <boB@k7iq.com> - 2017-08-17 13:42 -0700
      Re: Microchip ICD4 ? Lasse Langwadt Christensen <langwadt@fonz.dk> - 2017-08-17 14:23 -0700
        Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 17:46 -0400
      Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 17:44 -0400
        Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 18:40 -0400
          Re: Microchip ICD4 ? DemonicTubes <tlackie@gmail.com> - 2017-08-17 16:19 -0700
            Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 22:04 -0400
          Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 20:03 -0400
            Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 23:17 -0400
              Re: Microchip ICD4 ? "Michael A. Terrell" <mike.terrell@earthlink.net> - 2017-08-18 07:36 -0400
            Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-17 22:50 -0700
              Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-18 14:43 +0100
              Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 13:42 +0000
                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 12:49 -0400
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 17:11 +0000
                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 16:22 -0400
                Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-19 08:44 +0100
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:19 -0700
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-28 00:22 -0700
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-09-02 16:35 +0000
              Re: Microchip ICD4 ? Cecil Bayona <cbayona@cbayona.com> - 2017-08-18 10:58 -0500
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 09:34 -0700
            Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 13:22 +0200
              Re: Microchip ICD4 ? stephen@mpeforth.com (Stephen Pelc) - 2017-08-18 11:54 +0000
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 14:40 +0000
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 09:29 -0700
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 17:06 +0000
                Re: Microchip ICD4 ? Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-08-18 19:59 +0100
                Re: Microchip ICD4 ? dplatt@coop.radagast.org (Dave Platt) - 2017-08-18 12:49 -0700
                Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 01:52 +0200
                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 20:40 -0400
                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 20:43 -0400
                Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 13:03 +0200
                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-19 10:30 -0400
                Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 21:03 +0200
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:28 -0700
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:49 +0200
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:43 +0200
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:26 -0700
              Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 14:11 +0000
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:49 +0200
          Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 02:40 +0000
            Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 22:55 -0400
              Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 09:14 +0000
                Re: Microchip ICD4 ? jack4747@gmail.com - 2017-08-18 03:10 -0700
                Re: Microchip ICD4 ? Clive Arthur <cliveta@nowaytoday.co.uk> - 2017-08-18 11:38 +0100
                Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-18 12:13 +0100
                Re: Microchip ICD4 ? jack4747@gmail.com - 2017-08-18 04:25 -0700
                Re: Microchip ICD4 ? Clive Arthur <cliveta@nowaytoday.co.uk> - 2017-08-18 13:43 +0100
                Re: Microchip ICD4 ? Johann Klammer <klammerj@NOSPAM.a1.net> - 2017-08-18 23:40 +0200
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:57 +0200
                Re: Microchip ICD4 ? Przemek Klosowski <przemek@tux.dot.org> - 2017-08-22 03:24 +0000
                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 12:32 -0400
                Re: Microchip ICD4 ? Neon John <no@never.com> - 2017-08-18 10:02 -0400
                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 11:02 -0400
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:46 +0000
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:57 +0200
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:54 +0200
            Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 23:01 -0400
              Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 07:58 +0000
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 01:19 -0700
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 20:51 +0000
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:35 -0700
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:42 +0000
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-20 19:49 -0700
                Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-18 05:18 -0400
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:22 +0000
                Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-22 00:08 -0400
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-21 22:41 -0700
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-22 07:28 +0000
                Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-23 16:52 -0400
            Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-17 22:54 -0700
            Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:36 +0200
              Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 08:49 +0000
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 17:03 +0200
              Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-26 02:33 +0000
                Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-26 01:55 -0400
                Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-27 13:40 -0700
                Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-09-02 12:58 -0400
                Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-28 16:25 +0200
          Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 13:28 +0000
    Re: Microchip ICD4 ? speff <spehro@gmail.com> - 2017-08-17 19:09 -0700
    Re: Microchip ICD4 ? TTman <pcw1.cad@ntlworld.com> - 2017-08-18 10:12 +0100
      Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-18 05:21 -0400
        Re: Microchip ICD4 ? TTman <pcw1.cad@ntlworld.com> - 2017-08-18 12:10 +0100

csiph-web