Can C and C++ object files be linked into an executable?

2007-01-26 Thread Ray Hurst

Hi,
I have a code that is compiled in C and I need to link in C++ object 
files. I need to know if C++ object files created with a C++ compiler 
can be linked with C object files created with the C compiler.


I have never attempted this. I have either written the entire project in 
C or C++. I have mixed C code with C++ code by placing the C code in a 
namespace. I have also interfaced C++ code to C code by createing a C 
wrapper for the C++ object but everything was compiled with an C++ compiler.

Ray



Re: reading binarys

2007-01-26 Thread Ray Hurst

Jason,
I'm not sure what you are asking here.

It appears that you can do system dump of the internal state of the 
game. In which case the answer is yes.


A programmer plans his memory space when a program is written. Every 
address in RAM space has a specific variable. The heap (stack) is 
located at a specific address, etc.


If you have the source and the binaries you must also have the map file.
You can write a program to parse the map file which tells you location 
of variables and there type. That parse result is then used to parse the 
system dump (binary file) and output in human readable format.


Hope this answers what you asked.
Ray

Jason Erickson wrote:

I'm working on a project where every so often one of our games comes
back and we pull the ram off the game for saving, and sometimes for
anaylisis.  Currently the only varibles in ram that we can physically
look at are the static members.  The information that we would love to
get to is the heap memory and be able to know what dynamically
allocated structure that heap memory belongs to.

I have the source code, I have the binarys, I have the ram dumps, I
have the boards.  Our games have the ability to recover back to the
original state that they were in before a power hit, so even though
the memory is dynamically allocated, our code is the only running code
on the machine and since it runs the code in the same order every
time, the pointers get put into the same memory locations every time.

What I need to know, is there some way to read the binary with some
program to figure out which order everything in memory is being
allocated, so that I can write a program to read the memory dump and
figure out which memory locations belong to which pointer varibles.
Our code is written in C with litteraly tons of pointers.  It runs on
the i960 processor (yeah I know...soo old...but it works and it costs
a lot of money to change once its been approved).

Any ideas would be appricated to be able to read the binary to figure
out the order in which varibles get loaded onto the heap.





Re: Can C and C++ object files be linked into an executable?

2007-01-26 Thread Ray Hurst

They told me to go to the compiler writer newsgroup.
This isn't it?
Ray

Mike Stump wrote:

On Jan 26, 2007, at 3:54 PM, Ray Hurst wrote:
I have a code that is compiled in C and I need to link in C++ object 
files. I need to know if C++ object files created with a C++ compiler 
can be linked with C object files created with the C compiler.


Wrong list, you want help gcc-help is closer to being the right list.  
Yes, you can interlink any language with any other.






Re: Can C and C++ object files be linked into an executable?

2007-01-27 Thread Ray Hurst
Maybe everybody has misunderstood. These are tool issues not basic C 
programming. Object file format has nothing to do with C programming.

More specifically they are linker issues.

Is the ABI format different between C and C++ object files.
Ray

Joe Buck wrote:

On Fri, Jan 26, 2007 at 04:25:54PM -0800, Ray Hurst wrote:

They told me to go to the compiler writer newsgroup.


"They" told you wrong.  You don't need a compiler writer to answer
basic C++ programming questions.





Re: Can C and C++ object files be linked into an executable?

2007-01-27 Thread Ray Hurst

I think this was the answer I was looking for.
By the way, was this the correct place to post it?
Ray

Ferad Zyulkyarov wrote:

Hi,


If you want to phrase the question in terms of object file format and
linker issues, the answer is that the format is the same.

It's easy to see why: the compiler does not produce object files.  It
produces files containing assembly language.  The assembler produces
object files.  The C and C++ compilers use the same assembler.


Before passing the ball to the assembler the compiler does name
mangling. It is different for C and C++ and the actual problem at link
time comes from here. If you have C++ sources and can compile these
sources and later link with the C object files surround your method
declarations with

extern "C" {...}

This may help. If you don't have the c++ sources, create wrappers
either to C object files or C++. For now I don't know any other
alternative.





Re: gcc 4.1.1: char *p = "str" puts "str" into rodata

2007-01-28 Thread Ray Hurst

Shouldn't the compiler error out here.
The statement: p = "" should have been p = '\0';
Or does the compiler treat them as equivalent.

It seems that only characters should be assigned to char's and strings 
are illegal

Ray

Richard Guenther wrote:

On 1/28/07, Denis Vlasenko <[EMAIL PROTECTED]> wrote:

char p;
int main() {
p = "";
return 0;
}

Don't you think that "" should end up in rw data?


Why?  It's not writable after all.

Richard.