From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4C18D1D8.2060301@maht0x0r.net> Date: Wed, 16 Jun 2010 14:30:00 +0100 From: maht User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100510 Thunderbird/3.0.4 MIME-Version: 1.0 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [9fans] portability question Topicbox-Message-UUID: 34501096-ead6-11e9-9d60-3106f5b1d025 On 06/16/10 10:11, hugo rivera wrote: > Can someone clarify why the program included outputs 'AB000000' (as I > expect) on 32 bit systems and 'FFFFFFFFAB000000' on 64 bit systems? > where all those 1's came from? what's the portable way of doing this? > sorry for newbie questions like this. > > > unsigned long l; > unsigned char c; > > l = 0L; > c = 0xAB; > l |= c << 24; > printf("%lX\n", l); > > check the ASM, looks like c is being cast as signed and then sign extended into a long and then ORed with l. perhaps this would solve it : l |= ((unsigned long) c) << 24 But I can't check