Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error C2375 - redefinition; different linkage

Reply
Thread Tools

error C2375 - redefinition; different linkage

 
 
omnia neo
Guest
Posts: n/a
 
      04-23-2010
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 ?
 
Reply With Quote
 
 
 
 
Paul Bibbings
Guest
Posts: n/a
 
      04-23-2010
omnia neo <> writes:

> 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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      04-24-2010
On 04/24/10 01:34 AM, omnia neo wrote:
> 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.

--
Ian Collins
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      04-24-2010
* 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error C2375 - redefinition; different linkage omnia neo C Programming 6 04-23-2010 09:35 PM
c++ linkage vs c linkage ramasubramanian.rahul@gmail.com C++ 1 09-12-2008 11:41 AM
Linkage Error Morris Dovey C Programming 3 02-01-2008 05:25 PM
namespaces, linkage error, operator overloading jakester C++ 11 04-16-2007 08:05 AM
linkage error when initializing static member array Neno C++ 2 10-23-2004 10:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57