Missing optimization: mempcpy(3) vs memcpy(3)
Alejandro Colomar
alx.manpages@gmail.com
Mon Dec 12 17:15:18 GMT 2022
Hi Jakub,
On 12/12/22 17:09, Jakub Jelinek wrote:
> On Mon, Dec 12, 2022 at 04:56:27PM +0100, Alejandro Colomar wrote:
>> "Names beginning with ‘str’, ‘mem’, or ‘wcs’ followed by a lowercase letter
>> are reserved for additional string and array functions. See String and Array
>> Utilities."
>
> It is not that simple.
> mem*, str* and wcs* are just potentially reserved identifiers, they are only
> reserved if the implementation provided them.
To clarify:
While ISO C up to C17 had them fully reserved, ISO C23 will make them
potentially reserved identifiers. POSIX further fully reserves them again
(maybe next POSIX aligns with C23 on that; I don't know).
> And what we discuss here
> is how to reliably find out if it was an implementation that provided them,
> because in case of gcc the implementation is GCC and the C library and
> perhaps some other libraries too.
> gcc can be used with lots of different C libraries, and many don't implement
> mempcpy.
Well, if GCC can't know what the implementation provides, then we're in big
trouble. Me, being just a user-space programmer, only know of _GNU_SOURCE for
determining if the function is available at compile-time. :)
Any of the POSIX or ISO C feature_test_macro(7)s prior to C23 should also be
enough to tell the compiler that mem* identifiers are reserved, and therefore
possibly provided by libc.
mempcpy(3) Library Functions Manual mempcpy(3)
NAME
mempcpy, wmempcpy - copy memory area
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h>
void *mempcpy(void dest[restrict .n], const void src[restrict .n],
size_t n);
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <wchar.h>
wchar_t *wmempcpy(wchar_t dest[restrict .n],
const wchar_t src[restrict .n],
size_t n);
Cheers,
Alex
--
<http://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20221212/aa42bbc4/attachment.sig>
More information about the Gcc
mailing list