bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hmac-md5


From: Paul Eggert
Subject: Re: hmac-md5
Date: Thu, 06 Oct 2005 10:14:14 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Simon Josefsson <address@hidden> writes:

> Is there a portability requirement that 'char foo = 0xAA' end
> up with 10101010 in the memory buffer (void*)&foo?

No for C, but yes for POSIX.

The main problem with char * is that, in principle, an implementation
can dump core if you do something like "char *p; ...; *p = 128;",
because 128 isn't a valid char value if char is signed.  I don't know
of any practical implementations that crash, but some debugging
implementations might, and in some sense that's a good thing.

> I'm not sure about 'unsigned char*'.  Using 'unsigned char*' usually
> lead to plenty of signed/unsigned warnings sooner or later.

Yes, I try to avoid 'unsigned char *' for that reason'.  'unsigned
char' is fine though.  I generally do something like this if I want to
deal with values in the range 0 .. UCHAR_MAX:

      char *p = ... compute with p ...;
      unsigned char uc = *p;
      ... compute with uc ...

rather than use 'unsigned char *'.  It's a little more verbose but
avoids the warnings and it's perfectly portable.  The tricy part is
converting the unsigned char back to char.  But I'm usually lazy and
just store it (e.g., "*p = uc"): that works on all the hosts I know
about.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]