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


Groups > comp.lang.c > #35992

Re: htons, htonl, ntohs, ntohl

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: htons, htonl, ntohs, ntohl
Date 2013-08-27 18:54 -0400
Organization Self
Message-ID <521D2E2C.1040104@verizon.net> (permalink)
References <kv7jr7$eig$1@dont-email.me> <slrnl1pbsh.2m9.grahn+nntp@frailea.sa.invalid> <kvii24$kfn$1@dont-email.me> <kvj9n4$4ra$1@dont-email.me>

Show all headers | View raw


On 08/27/2013 06:36 PM, James Harris wrote:
...
>   p[0] + 256 * p[1]
>   p[0] + (p[1] << 8)
>   p[0] | p[1] << 8
> 
> Is any one of these more or less idiomatic than the others?
> 
> That aside, the latter two should be faster if the compiler does nothing 
> clever.

That's no necessarily true; I've heard rumors of machines where the
first one is the one that a naive compiler will generate the fastest
code for. Of course, compilers dumb enough to generate significantly
different code for those three expressions are pretty rare nowadays,
unless you deliberately disable optimization.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

htons, htonl, ntohs, ntohl "James Harris" <james.harris.1@gmail.com> - 2013-08-23 13:17 +0100
  Re: htons, htonl, ntohs, ntohl Siri Cruise <chine.bleu@yahoo.com> - 2013-08-23 05:34 -0700
  Re: htons, htonl, ntohs, ntohl James Kuyper <jameskuyper@verizon.net> - 2013-08-23 08:44 -0400
    Re: htons, htonl, ntohs, ntohl Keith Thompson <kst-u@mib.org> - 2013-08-23 08:36 -0700
      Re: htons, htonl, ntohs, ntohl James Kuyper <jameskuyper@verizon.net> - 2013-08-23 12:27 -0400
  Re: htons, htonl, ntohs, ntohl Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-23 09:52 -0600
    Re: htons, htonl, ntohs, ntohl glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-23 18:04 +0000
      Re: htons, htonl, ntohs, ntohl Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-23 15:24 -0600
        Re: htons, htonl, ntohs, ntohl Ian Collins <ian-news@hotmail.com> - 2013-08-24 11:22 +1200
        Re: htons, htonl, ntohs, ntohl glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-26 01:55 +0000
          Re: htons, htonl, ntohs, ntohl James Kuyper <jameskuyper@verizon.net> - 2013-08-25 22:03 -0400
          Re: htons, htonl, ntohs, ntohl Richard Damon <Richard@Damon-Family.org> - 2013-08-25 22:03 -0400
          Re: htons, htonl, ntohs, ntohl Ian Collins <ian-news@hotmail.com> - 2013-08-26 14:10 +1200
    Re: htons, htonl, ntohs, ntohl "James Harris" <james.harris.1@gmail.com> - 2013-08-23 21:16 +0100
      Re: htons, htonl, ntohs, ntohl Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-25 13:54 -0600
    Re: htons, htonl, ntohs, ntohl christian.bau@cbau.wanadoo.co.uk - 2013-08-30 10:58 -0700
      Re: htons, htonl, ntohs, ntohl Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-30 12:37 -0600
        Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-31 17:03 +0000
          Re: htons, htonl, ntohs, ntohl glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-31 18:13 +0000
            Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-31 20:52 +0000
          Re: htons, htonl, ntohs, ntohl Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-31 14:08 -0600
  Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-27 13:54 +0000
    Re: htons, htonl, ntohs, ntohl Stephen Sprunk <stephen@sprunk.org> - 2013-08-27 10:53 -0500
      Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-27 22:00 +0000
        Re: htons, htonl, ntohs, ntohl "James Harris" <james.harris.1@gmail.com> - 2013-08-27 23:15 +0100
          Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-28 11:10 +0000
            Re: htons, htonl, ntohs, ntohl James Kuyper <jameskuyper@verizon.net> - 2013-08-28 07:20 -0400
              Re: htons, htonl, ntohs, ntohl "James Harris" <james.harris.1@gmail.com> - 2013-08-28 12:47 +0100
                Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-31 16:40 +0000
      Re: htons, htonl, ntohs, ntohl "James Harris" <james.harris.1@gmail.com> - 2013-08-27 23:36 +0100
        Re: htons, htonl, ntohs, ntohl James Kuyper <jameskuyper@verizon.net> - 2013-08-27 18:54 -0400
        Re: htons, htonl, ntohs, ntohl Stephen Sprunk <stephen@sprunk.org> - 2013-08-27 21:02 -0500
          Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-28 14:10 +0000
            Re: htons, htonl, ntohs, ntohl Stephen Sprunk <stephen@sprunk.org> - 2013-08-28 15:06 -0500
            Re: htons, htonl, ntohs, ntohl christian.bau@cbau.wanadoo.co.uk - 2013-08-30 10:42 -0700
              Re: htons, htonl, ntohs, ntohl Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-31 11:49 +0000

csiph-web