This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bcopy -> memcpy/memmove transition proposal

| It is really ridiculous that gcc still uses the non-ANSI functions
| (such as bcopy), rather than the standard ANSI functions.  We all
| (I hope) agree this is bogus, but fixing them all is a hassle.

I fully agree.

In the past I have moved the IRC daemon (undernet) also to
ANSI functions and have had no problems.

Of course this daemon doesn't run on as many Operating Systems
as the GNU compiler, but in general it is compiled on a LOT, and
I never had any complaint.

Here is how I did it in that package:

1) In :

AC_CHECK_HEADERS(string.h memory.h)
AC_CHECK_FUNCS(strchr memcpy memmove)

2) Using the following in a header file which is included before
   all other #includes in all files:

#include <string.h>

#include <string.h>

#define strchr index
#define strrchr rindex

char *strchr(), *strrchr(), *strtok();

#include <memory.h>

#define memcpy(d, s, n) bcopy ((s), (d), (n))
#define memset(a, b, c) bzero((a), (c))		/* We ONLY use memset(x, 0, y) */

#if NEED_BZERO		/* This is not used yet - needs to be added to `configure' */
#define bzero(a, c) memset((a), 0, (c))		/* Some use it in FD_ZERO */

#endif /*HAVE_MEMCPY*/

#define memmove(d, s, n) bcopy ((s), (d), (n))

#endif /*STDC_HEADERS*/

3) Using in source without (compile) problems:

memset(s, 0, n) <-- Only used for filling with zero's.



* I only use memset() to fill with zero's, there might be Operating Systems that
  actually still don't have memset and which uses the bzero() instead :/.
  I wouldn't know actually :)

* There are Operating Systems which use `bzero()' in a macro FD_ZERO.
  Those Operating Systems also have bzero itself defined it seems (I didn't need
  to #define NEED_BZERO yet), it should be kept in mind thought that on
  machines like that it is impossible to ONLY use the mem-family (most also
  have memset).

* I didn't run into a machine yet that didn't have strtok().
  (Some have strtoken() (not ANSI), most don't).

I hope this was helpful,

 Carlo Wood  <>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]