9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] caveat... optimizer? the `zero and forget' thread on HN
Date: Mon, 29 Oct 2012 21:10:41 -0400	[thread overview]
Message-ID: <a7d7fa571d182bc1e59c2f91324be275@kw.quanstro.net> (raw)
In-Reply-To: <20121030003501.AE691B827@mail.bitblocks.com>

On Mon Oct 29 20:36:26 EDT 2012, bakul@bitblocks.com wrote:
> Not a question of fault but IMHO a programmer, like a
> carpenter or anyone who does real work, has to experiment and
> learn the strengths and weaknesses of his tools of his trade
> if he wants to become competent.
>
> The language standard can only mandate what you can do within
> the language.  For instace, if the blog writer had done this:
>
>     ...
>     memcpy(a, 0, sizeof a);
>     for (i = 0; i < sizeof a; i++)
> 	assert(a[i] == 0);
>     return 0;
> }
>
> He would have seen that every a[i] was indeed 0. But if you
> use means external to the language (such as used a debugger or
> look at the assembly language) to check side-effects, you get
> to see the underside of optimization. Ugly, confusing and
> possibly surprising. If you want to do something not covered
> in the standard, learn what the compiler does and find a
> compiler dependent way.

you are arguing for a cartoon hammer that runs away when you're
not looking at it.

> > and i can design a standards-compatable compiler that will break
> > most any c program.
>
> Care to give an example? I am genuinely interested. The C
> standard is far from perfect but it has worked well enough.
> [Where is doug gywn when we need him?]

oh, there are a number of obvious under-handed tricks.  let's see,
for an intel compiler, change the structure padding to something bizarre
like 3 bytes.  that will break a large number of linux drivers.  (the 57711
for sure!)  rearrange structure elements other than the first.
you can change from signed-preserving to unsigned preserving.
that'll catch a lot of folks out.  do ones-complement arithmetic
(i believe that's still legal).  have 10-bit bytes. 20 bit shorts, 40 bit
ints, 45-bit longs and 80-bit vlongs.  (i'm not sure that's completely
legal, but you get the point.)  make pointers to different types different
sizes.  the list goes on.  the combinations are silly, too.  default
unsigned characters with unsigned preserving behavior.  good luck
debugging that!

and since you would allow compilers to mess with side effects, we could
have a genuine field day.

> > what i think has broken down is common sense among compiler
> > writers.  they're too focused on being fast, and not focused enough
> > on being *useful*.
>
> I agree but I am afraid they do that because that is what the
> market demands.  Pretty much most of the software that the
> Internet runs on + used by most people + businesses uses C or
> C++ so C/C++ and their standards have been *useful* (but see
> below). Fast does matter when you scale up (a big company may
> need 18K servers instead of 20K and that results in savings
> and less heat generation).

i don't understand your use of the world "useful".  to me, the c
standard has become like a political issue.  it's something to
game for personal advantage.

- erik



  reply	other threads:[~2012-10-30  1:10 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-29  9:45 dexen deVries
2012-10-29 10:12 ` tlaronde
2012-10-29 13:43   ` erik quanstrom
2012-10-29 13:35 ` erik quanstrom
2012-10-29 22:35   ` Bakul Shah
2012-10-29 22:47     ` Charles Forsyth
2012-10-29 23:05       ` Bakul Shah
2012-10-29 23:07         ` erik quanstrom
2012-10-29 23:15           ` David Leimbach
2012-10-29 23:20             ` erik quanstrom
2012-10-29 23:53               ` andrey mirtchovski
2012-10-29 23:59                 ` Kurt H Maier
2012-10-29 23:10     ` erik quanstrom
2012-10-29 23:26       ` Bakul Shah
2012-10-29 23:31         ` Bakul Shah
2012-10-29 23:36         ` erik quanstrom
2012-10-29 23:58           ` Charles Forsyth
2012-10-30  0:52             ` Bakul Shah
2012-10-30  1:01               ` erik quanstrom
2012-10-30  7:55             ` tlaronde
2012-10-30  0:35           ` Bakul Shah
2012-10-30  1:10             ` erik quanstrom [this message]
2012-10-30  3:06               ` Bakul Shah
2012-10-30  3:16                 ` Corey Thomasson
2012-10-30 13:08                   ` erik quanstrom
2012-10-30 15:15                     ` arnold
2012-10-30  1:46             ` cinap_lenrek
2012-10-30  1:21         ` Kurt H Maier
2012-10-30  8:07         ` tlaronde
2012-10-30 10:26         ` Richard Miller
2012-10-30 10:39           ` dexen deVries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a7d7fa571d182bc1e59c2f91324be275@kw.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).