From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15894 invoked by alias); 12 Sep 2014 08:52:55 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19068 Received: (qmail 15674 invoked from network); 12 Sep 2014 08:52:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.2 Date: Fri, 12 Sep 2014 09:42:30 +0100 From: Dominik Vogt To: zsh-users@zsh.org Subject: Re: Determining the length of "long"? Message-ID: <20140912084230.GA4226@linux.vnet.ibm.com> Reply-To: vogt@linux.vnet.ibm.com Mail-Followup-To: zsh-users@zsh.org References: <20140911213608.GA1029@gmx.de> <140911213901.ZM21898@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <140911213901.ZM21898@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14091208-0342-0000-0000-000001081078 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