linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn@gclements.plus.com>
To: James Colannino <james@colannino.org>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: pointer arithmetic vs. arrays
Date: Sun, 26 Feb 2006 15:29:39 +0000	[thread overview]
Message-ID: <17409.51555.191516.793031@cerise.gclements.plus.com> (raw)
In-Reply-To: <44010CFF.5040806@colannino.org>


James Colannino wrote:

> Hey everyone.  I've heard (and have also read in "The C Programming 
> Language") that pointer arithmetic in place of arrays is, in general, 
> faster.  However, I've also heard that modern compilers automatically 
> make optimizations that account for this difference.
> 
> In everyone's opinion, taking both readability and issues of speed into 
> account, what is better to use?  I'd imagine this would depend on the 
> situation.  Just trying to pick up better coding habits as I learn :)

In most cases, I'd recommend array indexing.

If something can reasonably be expressed in either form, array
indexing is usually clearer (both to read and to debug), and compilers
which don't optimise array access are rare enough not to be worth
worrying about.

-- 
Glynn Clements <glynn@gclements.plus.com>

      reply	other threads:[~2006-02-26 15:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-26  2:05 pointer arithmetic vs. arrays James Colannino
2006-02-26 15:29 ` Glynn Clements [this message]

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=17409.51555.191516.793031@cerise.gclements.plus.com \
    --to=glynn@gclements.plus.com \
    --cc=james@colannino.org \
    --cc=linux-c-programming@vger.kernel.org \
    /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).