character strings, macros, ANSI c, multicharacter chars question

Barry Margolin barmar at think.com
Fri Jan 5 16:05:28 AEST 1990


In article <1990Jan4.190431.19748 at ultra.com> ted at ultra.com (Ted Schroeder) writes:
>Also, I would like to create an integer that is full of '+' characters
>i.e. on an ASCII machine the four byte integer would be 0x2b2b2b2b.  
>Unfortunately the code must run on both ASCII and EBCDIC machines.  
>Is there any portable way to do this?

I don't think this can be done fully portably, because you can't assume
that integers and chars are 32 and 8 bits wise, respectively.  If you're
will to be portably only to such systems (which is better than your
previous solution), I think the following will do it:

	'+'<<24 | '+'<<16 | '+'<<8 | '+'

You could also create a union of an integer and a four-character array full
of '+' characters.  This also isn't truly portable, but it will also work
on many systems.
--
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list