mem.h doesn't seem to be available in g++

S

Simon Elliott

I have some C code in a header which must be #included in both C and
C++ source files. The code in the header makes use of memcpy().

In bcb3 and bcb6, memcpy() needs <mem.h>. According to the g++ man page
for memcpy(), memcpy() needs <string.h>, and g++ complains that it
can't find <mem.h>

Is there anything in the standards which specify which header memcpy()
should require?

I'm aware of <cstring> but can't use it because this code must be both
valid C and C++

I don't want to end up with code which is stuffed full of #ifdef's for
all the different compilers I need to support. How do I deal with this
issue?
 
P

Pete Becker

Simon said:
Is there anything in the standards which specify which header memcpy()
should require?

I'm aware of <cstring> but can't use it because this code must be both
valid C and C++

It's declared in <string.h> and <cstring>.
 
V

Victor Bazarov

Simon said:
I have some C code in a header which must be #included in both C and
C++ source files. The code in the header makes use of memcpy().

In bcb3 and bcb6, memcpy() needs <mem.h>. According to the g++ man page
for memcpy(), memcpy() needs <string.h>, and g++ complains that it
can't find <mem.h>

Is there anything in the standards which specify which header memcpy()
should require?

Yes. 'memcpy' is available either in <cstring> or <string.h>. The former
is supposed to have it in 'std' namespace. The latter is supposed to have
it in both global and 'std' namespaces.
I'm aware of <cstring> but can't use it because this code must be both
valid C and C++

Use said:
I don't want to end up with code which is stuffed full of #ifdef's for
all the different compilers I need to support. How do I deal with this
issue?

Try to always use the common standard denominator. Be prepared though
to still have some #ifdef's in your code. It's inevitable. Not all
compilers support 100% of the language and quite a few simply have bugs.

V
 
M

Maxim Yegorushkin

I have some C code in a header which must be #included in both C and
C++ source files. The code in the header makes use of memcpy().

In bcb3 and bcb6, memcpy() needs <mem.h>. According to the g++ man page
for memcpy(), memcpy() needs <string.h>, and g++ complains that it
can't find <mem.h>

There is no standard header <mem.h>. C standard ISO/IEC 9899:1999 (E) in
7.21 states memcpy() is declared in <string.h>.
 
S

Simon Elliott

There is no standard header <mem.h>. C standard ISO/IEC 9899:1999 (E)
in 7.21 states memcpy() is declared in <string.h>.

Thanks for this. It turns out that memcpy() is declared in <string.h>
as well as <mem.h> in the Borland compilers, so I can simply change all
occurances of <mem.h> to <string.h> and have standard and portable code
with no #ifdefs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,284
Latest member
alphabetsalphabets

Latest Threads

Top