Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: character strings, macros, ANSI c, multicharacter chars question Keywords: string, multicharacter, ebcdic/ascii Message-ID: <15583@haddock.ima.isc.com> Date: 6 Jan 90 19:07:56 GMT References: <1990Jan4.190431.19748@ultra.com> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Distribution: na Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 22 In article <1990Jan4.190431.19748@ultra.com> ted@ultra.com (Ted Schroeder) writes: >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. First I'll mention the siamese character constant '++++', but only to disrecommend it. It'll probably give you the right answer, but you can't count on the compiler accepting it without a warning. Barry suggested ('+'<<24 | '+'<<16 | '+'<<8 | '+'); the briefer form (0x01010101 * '+') is equivalent. You can eliminate the byte- and word-size assumptions with the following (note that the result is cast-free, and hence usable at the preprocessor level, only if the compiler is ANSI): #if __STDC__ #include #else #define UINT_MAX (~(unsigned int)0) #define UCHAR_MAX ((unsigned char)UINT_MAX) #endif #define PLUS (UINT_MAX / UCHAR_MAX * '+') Karl W. Z. Heuer (karl@haddock.isc.com or ima!haddock!karl), The Walking Lint