Re: Read hex string to a buf
- From: Christopher Layne <clayne@xxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 01:18:48 -0800
Keith Thompson wrote:
hex2dec.c:39: warning: array subscript has type 'char'
Whoops, I should have paid more attention; I didn't realize the
subscripts were of type char (which can be signed on some
implementations). The values you're using happen to be guaranteed to
be positive, but the compiler understandably didn't figure that out.
I'm not sure size_t is the best type to convert to, but it's not
unreasonable. Or you might declare "set" as an array of unsigned
char.
Yep. It's of type char as I'm using it as a simple character hash. Anyways, I
agree that just using an array of unsigned char rather than char is cleaner
and achieves the same goal in the end. Unfortunately, it's a 'choose your
battle' as I'm using the same technique further down and changing 'q' to
unsigned char means it's now time to fight with casting argv[1]. But this
is only 1 cast vs 4, so comparitively a lesser deal.
In reference to size_t, I've always used this in situations related to array
indexing as I have always been under the impression size_t is guaranteed
to be able to represent an index value. Of course, things wouldn't go so well
if one of the characters within that above set were actually a negative
value - then again, casting to int wouldn't help either.
(gdb) p /d (size_t)(char)129
$1 = 4294967169
(gdb) p /d (int)(char)129
$2 = -127
Although I did have direct control over the characters I used in the set,
still a better decision to use unsigned char, agreed.
.
- 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
- Re: Read hex string to a buf
- From: Keith Thompson
- Read hex string to a buf
- Prev by Date: Re: Read hex string to a buf
- Next by Date: Re: OT: Google's latest dungheap
- Previous by thread: Re: Read hex string to a buf
- Next by thread: Re: Read hex string to a buf
- Index(es):
Relevant Pages
|