From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Length of Chars... Date: 24 Jan 2000 13:54:31 GMT Organization: Aachen University of Technology (RWTH) Lines: 44 Message-ID: <86hlin$e79$1@nets3.rz.RWTH-Aachen.DE> References: <3888ED7B DOT DF52FEB2 AT ou DOT edu> <38896068 DOT 8C5927C0 AT is DOT elta DOT co DOT il> <388A0530 DOT DF2B2F31 AT ou DOT edu> <83snzpq114 DOT fsf AT mercury DOT st DOT hmc DOT edu> <388A3F3A DOT 80C5F016 AT ou DOT edu> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 948722071 14569 137.226.32.75 (24 Jan 2000 13:54:31 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 24 Jan 2000 13:54:31 GMT User-Agent: tin/1.4-19991113 ("No Labels") (UNIX) (Linux/2.0.0 (i586)) Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com David Cleaver wrote: > So, would it better for me to store all of my one's and zero's in the > 'int' type to speed up operations, since all I'm doing is accessing the > arrays (I'm not changing anything in them), or should I just keep it in > the 'char' data type? See, the reason for the hex question was... > If I store all the info in hex form in the 'char' type, like: > 0xa4, 0x3c, 0xf2, 0x7d, then all I have to do to change it to 'int' is > combine them all into one hex unit (right?): > 0xa43cf27d The real problem you face, there, is that you want to use constant initializers (which are of fixed size, as written into the source code), for a datatype like 'int' which can be of different sizes, on different C platforms. I don't think that's a very good plan, to start with. At the very least, you should #include #if CHAR_BITS != 8 # error This code does not work on this platform! #endif or so, to make sure that the problem never goes unnoticed. Same for integer. You could assume 'int' to be 4 bytes, and check it like this: #include #if UINT_MAX != 4294967295U # error This code only works on platforms where int is 32bits! #endif Except for constant initializers in the source code, the optimal answer, of course, would be not to assume any particular size of the data type, but parametrizing your algorithm in units of CHAR_BITS*sizeof(int), i.e. the size of an integer, as the given platform has it. That would yield portable code. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.