Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Insert C code chunk in a big C++ program

Reply
Thread Tools

Insert C code chunk in a big C++ program

 
 
horacius.rex@gmail.com
Guest
Posts: n/a
 
      05-19-2007
Hi,

I don't know if it is better to post this question to a C or C++
group, so my apologies.

My general question:

I have a very big C++ program (Main.cpp) which compiles on machine X
with compiler XA++.

I also have a function whose source code (function.c) in C (not C++)
compiles on machine X with compiler XBcc.

XA++ and XBcc are compilers from different companies.

On machine Y I can do:

1- compilation of Main.cpp to object file Main.o using compiler Y++
2- compilation of function.c to objetc file function.o using compiler
Ycc

Compilers Y++ and Ycc come from the same company. "Y" could be for
instance the GNU compiler so we would have g++ and gcc.

3- Main.o sends input data to function.o and function.o returns
calculated data to Main.o. Now I link in some way Main.o with
function.o and create Program_in_Y.exe.

My general question is if I can do the same procedure in machine X.
Perhaps the same question is if objects created with different
compilers on the same machine can link in some way and create an
executable or binary file.

Thanks.

 
Reply With Quote
 
 
 
 
popyart@gmail.com
Guest
Posts: n/a
 
      05-19-2007
On May 19, 4:02 am, horacius....@gmail.com wrote:
> Hi,
>
> I don't know if it is better to post this question to a C or C++
> group, so my apologies.
>
> My general question:
>
> I have a very big C++ program (Main.cpp) which compiles on machine X
> with compiler XA++.
>
> I also have a function whose source code (function.c) in C (not C++)
> compiles on machine X with compiler XBcc.
>
> XA++ and XBcc are compilers from different companies.
>
> On machine Y I can do:
>
> 1- compilation of Main.cpp to object file Main.o using compiler Y++
> 2- compilation of function.c to objetc file function.o using compiler
> Ycc
>
> Compilers Y++ and Ycc come from the same company. "Y" could be for
> instance the GNU compiler so we would have g++ and gcc.
>
> 3- Main.o sends input data to function.o and function.o returns
> calculated data to Main.o. Now I link in some way Main.o with
> function.o and create Program_in_Y.exe.
>
> My general question is if I can do the same procedure in machine X.
> Perhaps the same question is if objects created with different
> compilers on the same machine can link in some way and create an
> executable or binary file.
>
> Thanks.



 
Reply With Quote
 
 
 
 
Branimir Maksimovic
Guest
Posts: n/a
 
      05-19-2007
On May 19, 1:40 pm, popy...@gmail.com wrote:
> On May 19, 4:02 am, horacius....@gmail.com wrote:
>
> > Hi,

>
> > I don't know if it is better to post this question to a C or C++
> > group, so my apologies.

>
> > My general question:

>
> > I have a very big C++ program (Main.cpp) which compiles on machine X
> > with compiler XA++.

>
> > I also have a function whose source code (function.c) in C (not C++)
> > compiles on machine X with compiler XBcc.

>
> > XA++ and XBcc are compilers from different companies.

........
> > 3- Main.o sends input data to function.o and function.o returns
> > calculated data to Main.o. Now I link in some way Main.o with
> > function.o and create Program_in_Y.exe.

>
> > My general question is if I can do the same procedure in machine X.
> > Perhaps the same question is if objects created with different
> > compilers on the same machine can link in some way and create an
> > executable or binary file.


Technically if both compilers produce same object format that
can link, only problem that remains is calling convention.
You can see if you can specify calling convention of interfacing
functions explicitelly. Another problem is, as if compilers don;t
have compatible calling conventions at all.
Then you are out of luck, as then you have to write thunks in
assembler that will forward parameters
and result between functions.
And of course you have to make sure that layout for parameters
and results match. eg long double for one compiler can be
64 bit and for other 80 bit, not to mention structs.
All in all tough luck. If you are not experienced in assembler
programming then it is easier to just compile both Main.cpp and
function.c (with possible corrections) with XA++.

Greetings, Branimir.

 
Reply With Quote
 
llothar
Guest
Posts: n/a
 
      05-19-2007
On 19 Mai, 18:02, horacius....@gmail.com wrote:
> Hi,
>
> I don't know if it is better to post this question to a C or C++
> group, so my apologies.
>
> My general question:
>
> I have a very big C++ program (Main.cpp) which compiles on machine X
> with compiler XA++.
>
> I also have a function whose source code (function.c) in C (not C++)
> compiles on machine X with compiler XBcc.
>
> XA++ and XBcc are compilers from different companies.
>
> On machine Y I can do:
>
> 1- compilation of Main.cpp to object file Main.o using compiler Y++
> 2- compilation of function.c to objetc file function.o using compiler
> Ycc
>
> Compilers Y++ and Ycc come from the same company. "Y" could be for
> instance the GNU compiler so we would have g++ and gcc.
>
> 3- Main.o sends input data to function.o and function.o returns
> calculated data to Main.o. Now I link in some way Main.o with
> function.o and create Program_in_Y.exe.
>
> My general question is if I can do the same procedure in machine X.
> Perhaps the same question is if objects created with different
> compilers on the same machine can link in some way and create an
> executable or binary file.
>
> Thanks.


Ah, a good homework question!

Normally every platform has a ABI which tells how to pass parameters
to a function etc.
If the compiler A obeys to this ABI and compiler 'B' does not you have
a problem otherwise
it might work (if the runtime functions are also compatible). You
might also have different
identifier names like preceding underscores.

For more information please use the references in the books list your
teacher gave you.

 
Reply With Quote
 
Barry
Guest
Posts: n/a
 
      05-19-2007

"Branimir Maksimovic" <> wrote in message
news: ups.com...
> On May 19, 1:40 pm, popy...@gmail.com wrote:
>> On May 19, 4:02 am, horacius....@gmail.com wrote:
>>
>> > Hi,

>>
>> > I don't know if it is better to post this question to a C or C++
>> > group, so my apologies.

>>
>> > My general question:

>>
>> > I have a very big C++ program (Main.cpp) which compiles on machine X
>> > with compiler XA++.

>>
>> > I also have a function whose source code (function.c) in C (not C++)
>> > compiles on machine X with compiler XBcc.

>>
>> > XA++ and XBcc are compilers from different companies.

> .......
>> > 3- Main.o sends input data to function.o and function.o returns
>> > calculated data to Main.o. Now I link in some way Main.o with
>> > function.o and create Program_in_Y.exe.

>>
>> > My general question is if I can do the same procedure in machine X.
>> > Perhaps the same question is if objects created with different
>> > compilers on the same machine can link in some way and create an
>> > executable or binary file.

>
> Technically if both compilers produce same object format that
> can link, only problem that remains is calling convention.
> You can see if you can specify calling convention of interfacing
> functions explicitelly. Another problem is, as if compilers don;t
> have compatible calling conventions at all.
> Then you are out of luck, as then you have to write thunks in
> assembler that will forward parameters
> and result between functions.
> And of course you have to make sure that layout for parameters
> and results match. eg long double for one compiler can be
> 64 bit and for other 80 bit, not to mention structs.
> All in all tough luck. If you are not experienced in assembler
> programming then it is easier to just compile both Main.cpp and
> function.c (with possible corrections) with XA++.
>
> Greetings, Branimir.
>

<OT>
"just compile both Main.cpp and
function.c (with possible corrections) with XA++"

This is probably the best guess solution. But you
can omit the corrections part if the compiler is also
a C compiler and the code is actually C.

This discussion is completely off topic for clc. So if you
really want an answer you should look at the documentation
for the compilers you plan to use.
</OT>


 
Reply With Quote
 
Branimir Maksimovic
Guest
Posts: n/a
 
      05-19-2007
On May 19, 3:10 pm, "Barry" <bar...@nullhighstream.net> wrote:
> "Branimir Maksimovic" <b...@hotmail.com> wrote in message
>
> news: ups.com...
>
> > On May 19, 1:40 pm, popy...@gmail.com wrote:
> >> On May 19, 4:02 am, horacius....@gmail.com wrote:

>
> >> > Hi,

>
> >> > I don't know if it is better to post this question to a C or C++
> >> > group, so my apologies.

>
> >> > My general question:

>
> >> > I have a very big C++ program (Main.cpp) which compiles on machine X
> >> > with compiler XA++.

>
> >> > I also have a function whose source code (function.c) in C (not C++)
> >> > compiles on machine X with compiler XBcc.

>
> >> > XA++ and XBcc are compilers from different companies.

> > .......
> >> > 3- Main.o sends input data to function.o and function.o returns
> >> > calculated data to Main.o. Now I link in some way Main.o with
> >> > function.o and create Program_in_Y.exe.

>
> >> > My general question is if I can do the same procedure in machine X.
> >> > Perhaps the same question is if objects created with different
> >> > compilers on the same machine can link in some way and create an
> >> > executable or binary file.

>
> > Technically if both compilers produce same object format that
> > can link, only problem that remains is calling convention.
> > You can see if you can specify calling convention of interfacing
> > functions explicitelly. Another problem is, as if compilers don;t
> > have compatible calling conventions at all.
> > Then you are out of luck, as then you have to write thunks in
> > assembler that will forward parameters
> > and result between functions.
> > And of course you have to make sure that layout for parameters
> > and results match. eg long double for one compiler can be
> > 64 bit and for other 80 bit, not to mention structs.
> > All in all tough luck. If you are not experienced in assembler
> > programming then it is easier to just compile both Main.cpp and
> > function.c (with possible corrections) with XA++.

>
> > Greetings, Branimir.

>
> <OT>
> "just compile both Main.cpp and
> function.c (with possible corrections) with XA++"
>
> This is probably the best guess solution. But you
> can omit the corrections part if the compiler is also
> a C compiler and the code is actually C.


This reminds why is bad to answer messages that are
crossposted

>
> This discussion is completely off topic for clc. So if you
> really want an answer you should look at the documentation
> for the compilers you plan to use.


I guess OP already did that, but yet he/she don;t knows the answer.
OTOH this naive question, speaks that either OP is totally
clueless or is perfect troll

Greetings, Branimir.

 
Reply With Quote
 
David Wade
Guest
Posts: n/a
 
      05-19-2007

<> wrote in message
news: oups.com...
> Hi,
>
> I don't know if it is better to post this question to a C or C++
> group, so my apologies.
>
> My general question:
>
> I have a very big C++ program (Main.cpp) which compiles on machine X
> with compiler XA++.
>
> I also have a function whose source code (function.c) in C (not C++)
> compiles on machine X with compiler XBcc.
>
> XA++ and XBcc are compilers from different companies.
>
> On machine Y I can do:
>
> 1- compilation of Main.cpp to object file Main.o using compiler Y++
> 2- compilation of function.c to objetc file function.o using compiler
> Ycc
>
> Compilers Y++ and Ycc come from the same company. "Y" could be for
> instance the GNU compiler so we would have g++ and gcc.
>
> 3- Main.o sends input data to function.o and function.o returns
> calculated data to Main.o. Now I link in some way Main.o with
> function.o and create Program_in_Y.exe.
>
> My general question is if I can do the same procedure in machine X.
> Perhaps the same question is if objects created with different
> compilers on the same machine can link in some way and create an
> executable or binary file.
>


There is no gaurentee you can do this with arbitary comilers, though in
practice its often possible. Consider the case for machines where there is
no natural stack, e.g. IBM370. Even of both implementations use the same
register as the stack pointer, one could build the stack from low memory up,
another from high memory down....

> Thanks.
>



 
Reply With Quote
 
Thomas J. Gritzan
Guest
Posts: n/a
 
      05-19-2007
schrieb:
> Hi,
>
> I don't know if it is better to post this question to a C or C++
> group, so my apologies.


To a platform specific or compiler specific newsgroup.

> My general question:
>
> I have a very big C++ program (Main.cpp) which compiles on machine X
> with compiler XA++.
>
> I also have a function whose source code (function.c) in C (not C++)
> compiles on machine X with compiler XBcc.
>
> XA++ and XBcc are compilers from different companies.


In general, object files from two different compilers from two different
companies don't link together.

Why didn't you try if compiler Y can compile for your platform X also? If
it is GNU g++/gcc, if can compile for many platforms.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-19-2007
wrote:
> Hi,
>
> I don't know if it is better to post this question to a C or C++
> group, so my apologies.
>
> My general question:
>
> I have a very big C++ program (Main.cpp) which compiles on machine X
> with compiler XA++.
>
> I also have a function whose source code (function.c) in C (not C++)
> compiles on machine X with compiler XBcc.
>
> XA++ and XBcc are compilers from different companies.
>
> On machine Y I can do:
>
> 1- compilation of Main.cpp to object file Main.o using compiler Y++
> 2- compilation of function.c to objetc file function.o using compiler
> Ycc
>
> Compilers Y++ and Ycc come from the same company. "Y" could be for
> instance the GNU compiler so we would have g++ and gcc.
>
> 3- Main.o sends input data to function.o and function.o returns
> calculated data to Main.o. Now I link in some way Main.o with
> function.o and create Program_in_Y.exe.
>
> My general question is if I can do the same procedure in machine X.
> Perhaps the same question is if objects created with different
> compilers on the same machine can link in some way and create an
> executable or binary file.
>

Provided the C functions are declared as extern "C" to the C++ code, you
shouldn't have a problem. It is standard practice for all native C
compilers to use the came calling conventions on a particular machine.
A C compiler that didn't would be next to useless as it wouldn't be able
to generate code that used the native libraries.

--
Ian Collins.
 
Reply With Quote
 
Ernie Wright
Guest
Posts: n/a
 
      05-19-2007
Ian Collins wrote:

> It is standard practice for all native C compilers to use the came
> calling conventions on a particular machine. A C compiler that didn't
> would be next to useless as it wouldn't be able to generate code that
> used the native libraries.


One might think so, but I know of at least one counterexample, and it
certainly wouldn't surprise me if there were others.

The Win32 API contains no function that returns a floating-point value,
so no convention arose about how to do that. Given the following,

double foo( void );
double result;
result = foo();

the returned value is handled by Microsoft Visual C++ and Watcom 10.0
in different ways.

MSVC: call foo
fstp result ; pop ST(0) into result

Watcom: call foo
mov result, eax ; move edx:eax into result
mov result+4, edx

- Ernie http://home.comcast.net/~erniew
 
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
sending a file chunk by chunk instead as a whole to a web server Sanjeeb Python 3 08-03-2010 05:52 AM
GIDS 2009 .Net:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf ASP .Net 0 12-26-2008 09:29 AM
GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf Python 0 12-24-2008 07:35 AM
Insert C code chunk in a big C++ program horacius.rex@gmail.com C Programming 14 05-21-2007 10:41 PM
What is an AVI Chunk Viewer? - AVI Chunk Viewer.jpg (0/1) mazdra76@yahooo.com Computer Support 1 03-17-2006 02:52 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