pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Volkan YAZICI <volkan.yazici@gmail.com>
To: PostgreSQL Interfaces <pgsql-interfaces@postgresql.org>
Subject: Network Byte Order Coercion
Date: Mon, 16 May 2005 13:12:37 +0300
Message-ID: <7104a73705051603121f1c35ab@mail.gmail.com> (raw)

Hi,

In libpq example program 3 (testlibpq3.c), an int4 field is converted
to host byte order:

{{{
/* Get the field values (we ignore possibility they are null!) */
iptr = PQgetvalue(res, i, i_fnum);

/*
 * The binary representation of INT4 is in network byte order,
 * which we'd better coerce to the local byte order.
 */
ival = ntohl(*((uint32_t *) iptr));
}}}

(As I saw while reading "An Essay on Endian Order" [1]) I'm not so
familiar with byte orders, but what's the point of coercion in here?
Should we do it in every integer field we retrieved? What's the
[dis]advantages of this? I'd be so appreciated for any explanation.

[1] http://www.cs.umass.edu/~verts/cs32/endian.html

Regards.



view thread (2+ messages)  latest in thread

Message-ID: <7104a73705051603121f1c35ab@mail.gmail.com>
Permalink:  ../7104a73705051603121f1c35ab@mail.gmail.com/
Also on:    postgresql.org/message-id/7104a73705051603121f1c35ab@mail.gmail.com

 · 

reply

Reply instructions:

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

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: volkan.yazici@gmail.com
  Subject: Re: Network Byte Order Coercion
  In-Reply-To: <7104a73705051603121f1c35ab@mail.gmail.com>

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

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox