Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Determining the length of "long"?



Sorry, but I disagree. Zsh is absolutely the wrong tool for this task
unless you're striving for an unmaintainable, obfuscated, brittle script.
Please ask your peers, preferably including someone in the Linux level
three support org (where I used to work at IBM), for feedback on your idea.

P.S.., I would only use perl if there wasn't a better option. But perl is
preferable to zsh for this task and python is even better.

On Fri, Sep 12, 2014 at 1:42 AM, Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx>
wrote:

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


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank


Messages sorted by: Reverse Date, Date, Thread, Author