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


Groups > comp.lang.c > #26629

Re: packed structs

From JohnF <john@please.see.sig.for.email.com>
Newsgroups comp.lang.c
Subject Re: packed structs
Date 2012-09-24 02:54 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <k3oi08$14i$1@reader1.panix.com> (permalink)
References (1 earlier) <k3jaun$8al$1@dont-email.me> <k3jmbi$qgf$1@reader1.panix.com> <k3ne96$bja$1@dont-email.me> <k3o5mb$1ib$1@reader1.panix.com> <0.6562e3f0e92d8c6a2354.20120924015911BST.871uhs2q3k.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> JohnF <john@please.see.sig.for.email.com> writes:
> <snip>
>>    By the way, compared with those pack/unpack formats, I think
>> smemf()'s format string syntax is a lot more C/sprintf-like
>> (could you be more specific?). That's, of course, the trick:
>> access all functionality from a format string syntax that's
>> immediately intuitively sensible to both (a)people already
>> familiar with perl and/or python pack/unpack and maybe C/sprintf,
>> as well as (b)people only familiar with C/sprintf. Since I'm a
>> b-type myself, and wasn't even aware of the a-types until
>> brought to my attention here, the C/sprintf look-alike was
>> my sole original goal (which I'd thought was pretty successful,
>> modulo the minimal unavoidable syntax differences due to
>> fundamental functional requirements differences).
> 
> The main departure from sprintf is that literal characters are not
> copied to the destination.  That's going to look very odd at first
> glance.

Impossible to avoid (I think): what are you supposed to do with
  smemf(mem,"deaf"); ?
Is that 4 ascii chars or two hex bytes? Somehow, the
user has specify what he wants. My solution:
  smemf(mem,"deaf %s"); or smemf(mem,"deaf %x");
where a format specification preceded by a literal
is applied to that literal rather than eating the next arg.
If you've got a better idea, please follow up... consider
that both a request and a challenge. I tried and failed
to think of any better idea. But I'd be grateful for one.
I can (probably) code it, but I can't think of it.

> The main departure from pack/unpack is the lack of support for
> alternative byte orderings.  As a result, I'm not sure it's all that
> close to either familiar "model".

It does have little/big-endian support as an extra %d flag.
In the middle of the state machine parsing the format string...
  /* --- endian option flags (for %d) --- */
  case 'l': case 'L': endian = (-1); break; /* little-endian */
  case 'b': case 'B': endian = (+1); break; /* or big-endian */
  case 'e': case 'E': endian = ENDIAN; break; /*or whatever machine uses*/
I just didn't document it very well in the comments yet.
Sorry about that. I have a back-and-forth technique between
writing up the functional specs as comments in enough detail
to get going, then writing some code to see how it works,
then returning to the comments to fix them up or add some more
or whatever, etc, etc.
   It was primarily smemf()'s general idea I wanted to get across
by posting that comment block. Obviously, any shortcomings
in the specific functional details can be corrected and coded.
Of course, when I originally posted those comments, I wasn't
yet aware of python/perl pack and unpack. In that case, I could
have gotten across the general idea just by mentioning those.
-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

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


Thread

packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-22 01:54 +0000
  Re: packed structs Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-21 23:22 -0400
    Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-22 06:37 +0000
      Re: packed structs "BartC" <bc@freeuk.com> - 2012-09-22 13:47 +0100
        Re: packed structs Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-22 14:00 +0100
        Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-22 15:42 +0000
      Re: packed structs Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-22 09:13 -0400
      Re: packed structs Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-09-23 03:10 +0200
        Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-23 02:10 +0000
      Re: packed structs Stephen Sprunk <stephen@sprunk.org> - 2012-09-23 11:44 -0500
        Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-23 23:23 +0000
          Re: packed structs Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-24 01:59 +0100
            Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-24 02:54 +0000
              Re: packed structs Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-24 04:38 +0100
                Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-24 04:07 +0000
                Re: packed structs Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-24 12:16 +0100
                Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-24 11:45 +0000
              Re: packed structs "BartC" <bc@freeuk.com> - 2012-09-24 10:18 +0100
                Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-24 11:04 +0000
                Re: packed structs Stephen Sprunk <stephen@sprunk.org> - 2012-09-30 14:21 -0500
                Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-10-01 07:34 +0000
          Re: packed structs Stephen Sprunk <stephen@sprunk.org> - 2012-09-30 13:52 -0500
    Re: packed structs Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-09-22 01:31 -0700
      Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-22 08:53 +0000
        Re: packed structs Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-09-22 14:17 +0000
          Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-22 15:33 +0000
            Re: packed structs Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-09-22 20:43 +0000
            Re: packed structs "BartC" <bc@freeuk.com> - 2012-09-22 22:52 +0100
          Re: packed structs Keith Thompson <kst-u@mib.org> - 2012-09-22 13:47 -0700
            Re: packed structs JohnF <john@forkosh.com.com> - 2012-09-23 00:19 +0000
              Re: packed structs Ian Collins <ian-news@hotmail.com> - 2012-09-23 13:32 +1200
                Re: packed structs JohnF <john@please.see.sig.for.email.com> - 2012-09-23 02:16 +0000
        Re: packed structs Ian Collins <ian-news@hotmail.com> - 2012-09-23 10:33 +1200
          Re: packed structs Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-09-23 01:38 -0700
  Re: packed structs The Great Firewall of China Blue <chine.bleu@yahoo.com> - 2012-09-21 21:29 -0700

csiph-web