Re: Read hex string to a buf
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 08:36:06 +0000
Christopher Layne wrote, On 31/01/07 08:01:
Keith Thompson wrote:
The <unistd.h> header is non-portable, and your program doesn't use it
anyway.
Habit.
const size_t minl = 2;You accept hexadecimal digits in either upper or lower case, but you
const size_t nibl = 4;
const char delim[2] = "0x";
const char set[2][16] = { "0123456789abcdef", "0123456789ABCDEF" };
don't do the same for "0x" vs. "0X".
Sigh.
/* Make Keith Thompson Happy */
if (q[0] == '0' && (q[1] == 'x' || q[1] == 'X')) {
q += minl; l -= minl;
}
Consistency of operation is important.
These casts (like most casts) are unnecessary. An array index can be
of any integer type.
$ cc -g3 -O3 -W -Wall -Werror -pedantic -o hex2dec hex2dec.c
cc1: warnings being treated as errors
hex2dec.c: In function 'main':
hex2dec.c:25: warning: array subscript has type 'char'
hex2dec.c:26: warning: array subscript has type 'char'
hex2dec.c:38: warning: array subscript has type 'char'
hex2dec.c:39: warning: array subscript has type 'char'
So? Compilers are allowed to warn about perfectly good code. In my case, for serious work, I have that warning disabled.
(I haven't really looked at most of your program; a couple of thingsGood ole comp.lang.c. Quick to point out any error. Care to add anything else?
just jumped out at me.)
Maybe.
--
Flash Gordon
.
- References:
- Read hex string to a buf
- From: cppbeginner
- Re: Read hex string to a buf
- From: Christopher Layne
- Re: Read hex string to a buf
- From: Keith Thompson
- Re: Read hex string to a buf
- From: Christopher Layne
- Read hex string to a buf
- Prev by Date: Re: Read hex string to a buf
- Next by Date: Re: How to improve this sort?
- Previous by thread: Re: Read hex string to a buf
- Next by thread: Re: Read hex string to a buf
- Index(es):
Relevant Pages
|