Re: Read hex string to a buf



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;
const size_t nibl = 4;
const char delim[2] = "0x";
const char set[2][16] = { "0123456789abcdef", "0123456789ABCDEF" };
You accept hexadecimal digits in either upper or lower case, but you
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 things
just jumped out at me.)
Good ole comp.lang.c. Quick to point out any error. Care to add anything else?

Maybe.
--
Flash Gordon
.



Relevant Pages

  • Re: Read hex string to a buf
    ... hex2dec.c:25: warning: array subscript has type 'char' ... Either way, something will be cast. ...
    (comp.lang.c)
  • Re: Read hex string to a buf
    ... You accept hexadecimal digits in either upper or lower case, ... hex2dec.c:25: warning: array subscript has type 'char' ...
    (comp.lang.c)
  • Re: Read hex string to a buf
    ... hex2dec.c:25: warning: array subscript has type 'char' ... Either way, something will be cast. ...
    (comp.lang.c)
  • Re: somebody dropped a (warning) bomb
    ... And THAT is the fundamental problem with that *idiotic* warning. ... to say "I want a char of indeterminate sign". ... The kernel already uses isxxxthat are macros ... for doing strings. ...
    (Linux-Kernel)
  • Re: Read hex string to a buf
    ... hex2dec.c:25: warning: array subscript has type 'char' ... Here you have a real reason for using a cast, ...
    (comp.lang.c)