zsh-users
 help / color / mirror / code / Atom feed
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
To: zsh-users@zsh.org
Subject: Re: Determining the length of "long"?
Date: Fri, 12 Sep 2014 09:42:30 +0100	[thread overview]
Message-ID: <20140912084230.GA4226@linux.vnet.ibm.com> (raw)
In-Reply-To: <140911213901.ZM21898@torch.brasslantern.com>

On Thu, Sep 11, 2014 at 07:58:29PM -0700, Kurtis Rader wrote:
> There may be a way but why? A command shell is the wrong tool for
> that task.

To give you a bit of background:  The script is an fvwm module,
and apart from the need of sending two longs to the window manager
core in binary format, the shell is absolutely the right tool here
(combine several unix command line programs in a pipe, filter their
output and generate a wm command from that).

> You don't need to compile a C program to do this. If you have perl or
> python it's an almost trivial problem.

I know, but I never do something in perl if it can be done in zsh.

On Thu, Sep 11, 2014 at 09:39:01PM -0700, Bart Schaefer wrote:
> if (( ${#:-"$(( [#2] (1<<31)))"} > ${#:-"$(( [#2] (1<<63)))"} ))
> then print "zsh integer type is 32 bits"
> elif (( ${#:-"$(( [#2] (1<<63)))"} > ${#:-"$(( [#2] (1<<64)))"} ))
> then print "zsh integer type is 64 bits"
> else print "zsh integer type is more than 64 bits"
> fi

Hm, I'm not really sure that works reliably because the shift
amount may be truncated before it is used.  I.e. on s390 "1 << 32"
and "1 << 64" and "1 << 0" are all the same.  Luckily I don't need
that on s390.

> There's no guarantee that zsh's integer type is "long", so no, there
> is not.

If long is not guaranteed, how does zsh determine which integer
type it uses in arithmetic?  Would it use long long if a long is
four bytes and long long is available?

Is it possible to print pointers or memory contents in zsh?

> setopt C_BASES
> integer i=0x12345
> while (( i )) {
>   printf '\\\\x%x\n' $(( [#16] (i & 0xff) ))
>   (( i = i >> 8 ))
> }

Actually the amount I have to print is just a byte, but with
three or seven null bytes before or after it, so all I really
need to know is the host byte order to pick the right variant.
But that is only a bonus for now.
 
Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany


  reply	other threads:[~2014-09-12  8:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11 21:36 Dominik Vogt
2014-09-12  2:58 ` Kurtis Rader
2014-09-12  4:39 ` Bart Schaefer
2014-09-12  8:42   ` Dominik Vogt [this message]
2014-09-12 13:17     ` Kurtis Rader
2014-09-12 23:16     ` Bart Schaefer
2014-09-12 23:42       ` Dominik Vogt
2014-09-13  0:17         ` Bart Schaefer
2014-09-12  8:51   ` Peter Stephenson
2014-09-12 16:17 ` Roman Neuhauser
2014-09-12 17:04   ` Dominik Vogt
2014-09-12 18:10     ` Roman Neuhauser
2014-09-12 18:50       ` Dominik Vogt

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=20140912084230.GA4226@linux.vnet.ibm.com \
    --to=vogt@linux.vnet.ibm.com \
    --cc=zsh-users@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).