Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

on linux c c++ mixing issue from c file called cpp function and global variable address diffrent from c and cpp [closed]

$
0
0

I am trying to call c++ function from c on Linux(Centos 6.9) and GCC version is 2.96 and optimization is off

on windows, function working perfectly. However, on Linux, address of global variable changed and working bad.

Animal.h

class CAnimal
{
public:
void CDoSomething(const int ID);
};

#ifdef __cplusplus 
 extern "C"{
#endif //__cplusplus
 void DoSomething(const int ID);
#ifdef __cplusplus 
}
#endif //__cplusplus

Animal.cpp

 extern Animal[2048];

 void CAnimal::CDoSomething(const int ID)
{

// Animal is global

// Animal address changed!!

// In this, Animal[ID] address 0x0100

// working bad!

  Animal[ID].something;

}

void DoSomething(const int ID)
{
  CAnimal animal;
  animal.CDoSomething(ID);
 }

object.h

typedef struct stANIMAl
{
int a;
char* b;
and etc..

}ANIMAL;

ANIMAL Animal[2048];

func.h

void Do(void);

func.c

extern Animal[2048];

void Do(void)
{
// Animal[ID] address 0x0000
 DoSomething(0);
}

Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>