Re: Read hex string to a buf



Christopher Layne wrote:
CBFalconer wrote:

$ 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'

Yup. It's talking about set, and pointing out your error. Try
defining set as either signed or unsigned char. As usual, a cast
is probably an error.

Hah, you guys. We've hashed the angles about 4 different ways :).

Either way, something will be cast. If it's not the array indices, it's
strlen() and/or assigment from argv[1] to q.

(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?

Yup. Wrong specification for printing an uncast size_t in your
printf statement. Here you have a real reason for using a cast,
at least in C90.

You're right on that one - and I usually cast to unsigned long and
use "%lu", it just so coincidentally happened that I didn't use
"%lu", and on my host "%u" results in no warnings.

Note that AFAICS all your errors are due to casts, the misuse of.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

.



Relevant Pages