bug-gnulib
[Top][All Lists]
Advanced

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

Re: memxor


From: Simon Josefsson
Subject: Re: memxor
Date: Thu, 06 Oct 2005 13:20:24 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Paul Eggert <address@hidden> writes:

> Simon Josefsson <address@hidden> writes:
>
>> I am not sure about the prototype.  Should it use 'char*'?  'int*'?
>
> If its name is mem* then it should use void *, for consistency.
>
> The current implementation uses 'restrict', so memxor.m4 should
> AC_REQUIRE([gl_C_RESTRICT]) and the memxor module should depend on the
> restrict module.

The module depend on restrict, but the AC_REQUIRE in m4 wasn't
present.  I added it.  But is it necessary?  Shouldn't depending on
the restrict module be sufficient?

> The current implementation casts 'const void *' to 'char *', which
> will provoke warnings with many compilers.  Also, it contains
> unnecessary casts.  How about this implementation instead?
>
>   char *d = dest;
>   char const *s = src;
>
>   for (; n > 0; n--)
>     *d++ ^= *s++;
>
>   return dest;

Thanks, I installed the following:

--- memxor.c    05 Oct 2005 16:57:55 +0200      1.2
+++ memxor.c    06 Oct 2005 13:18:31 +0200      
@@ -27,10 +27,11 @@
 void *
 memxor (void *restrict dest, const void *restrict src, size_t n)
 {
+  char const *s = src;
   char *d = dest;
 
   for (; n > 0; n--)
-    *(char*)d++ ^= *(char*)src++;
+    *d++ ^= *s++;
 
   return dest;
 }




reply via email to

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