error C2375 - redefinition; different linkage

O

omnia neo

Hello,

I am trying to redirect the standard malloc and calloc defined in
stdlib.h to myown implementation MyMalloc amd MyCalloc. Following is
my impementation:

\\MyMemory.c
#include MyMemory.h /*implementation of MyMalloc() and MyCalloc()*/
#define malloc MyMalloc

But when i compile my code in VisualStudios I get following error:
...\VC\include\stdlib.h(601) : error C2375: 'MyMalloc' : redefinition;
different linkage
...\MyMemory.h(41) : see declaration of 'MyMalloc'

Please help me know how do I redirect the standard calls ?
 
P

Paul Bibbings

omnia neo said:
Hello,

I am trying to redirect the standard malloc and calloc defined in
stdlib.h to myown implementation MyMalloc amd MyCalloc. Following is
my impementation:

\\MyMemory.c
#include MyMemory.h /*implementation of MyMalloc() and MyCalloc()*/
#define malloc MyMalloc

But when i compile my code in VisualStudios I get following error:
..\VC\include\stdlib.h(601) : error C2375: 'MyMalloc' : redefinition;
different linkage
..\MyMemory.h(41) : see declaration of 'MyMalloc'

Well, can we? "See declaration of 'MyMalloc'," that is?
Please help me know how do I redirect the standard calls ?

Regards

Paul Bibbings
 
I

Ian Collins

Hello,

I am trying to redirect the standard malloc and calloc defined in
stdlib.h to myown implementation MyMalloc amd MyCalloc. Following is
my impementation:

\\MyMemory.c
#include MyMemory.h /*implementation of MyMalloc() and MyCalloc()*/
#define malloc MyMalloc

But when i compile my code in VisualStudios I get following error:
..\VC\include\stdlib.h(601) : error C2375: 'MyMalloc' : redefinition;
different linkage
..\MyMemory.h(41) : see declaration of 'MyMalloc'

Please help me know how do I redirect the standard calls ?

By heeding the compiler's error message and using the appropriate
linkage. Without seeing your declaration, my best guess is your
function is a C++ function, whereas malloc had extern "C" linkage.
Saying that, the error isn't very helpful.
 
A

Alf P. Steinbach

* omnia neo:
Hello,

I am trying to redirect the standard malloc and calloc defined in
stdlib.h to myown implementation MyMalloc amd MyCalloc. Following is
my impementation:

\\MyMemory.c
#include MyMemory.h /*implementation of MyMalloc() and MyCalloc()*/
#define malloc MyMalloc

But when i compile my code in VisualStudios I get following error:
..\VC\include\stdlib.h(601) : error C2375: 'MyMalloc' : redefinition;
different linkage
..\MyMemory.h(41) : see declaration of 'MyMalloc'

Please help me know how do I redirect the standard calls ?

In C++ 'malloc' is seldom used directly.

It *may* be used indirectly by C++ allocation, but that's an implementation detail.

To redirect C++ allocation you overload or define the allocation and
deallocation functions, 'operator new', 'operator new[]', 'operator delete' and
'operator delete[]'.

You can overload the global ones, and/or define/overload per class.

Make sure that you never return nullpointers but instead throw std::bad_alloc.


Cheers & hth.,

- Alf
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top