error C2375 - redefinition; different linkage

Discussion in 'C++' started by omnia neo, Apr 23, 2010.

  1. omnia neo

    omnia neo Guest

    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 ?
     
    omnia neo, Apr 23, 2010
    #1
    1. Advertising

  2. 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
     
    Paul Bibbings, Apr 23, 2010
    #2
    1. Advertising

  3. omnia neo

    Ian Collins Guest

    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
     
    Ian Collins, Apr 24, 2010
    #3
  4. * 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
     
    Alf P. Steinbach, Apr 24, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gernot Frisch

    redefinition, different types

    Gernot Frisch, Sep 13, 2004, in forum: C++
    Replies:
    13
    Views:
    2,231
    Jerry Coffin
    Sep 14, 2004
  2. Replies:
    4
    Views:
    3,637
    James Kanze
    Aug 5, 2008
  3. Replies:
    1
    Views:
    598
    Michael DOUBEZ
    Sep 12, 2008
  4. merrittr
    Replies:
    0
    Views:
    1,590
    merrittr
    Oct 9, 2009
  5. omnia neo

    error C2375 - redefinition; different linkage

    omnia neo, Apr 23, 2010, in forum: C Programming
    Replies:
    6
    Views:
    3,055
    ImpalerCore
    Apr 23, 2010
Loading...

Share This Page