473,783 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert C code chunk in a big C++ program

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.ex e.

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.

May 19 '07 #1
16 2885
On May 19, 4:02 am, horacius....@gm ail.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.ex e.

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.

May 19 '07 #2
On May 19, 1:40 pm, popy...@gmail.c om wrote:
On May 19, 4:02 am, horacius....@gm ail.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.ex e.
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.

May 19 '07 #3
On 19 Mai, 18:02, horacius....@gm ail.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.ex e.

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.

May 19 '07 #4

"Branimir Maksimovic" <bm***@hotmail. comwrote in message
news:11******** *************@k 79g2000hse.goog legroups.com...
On May 19, 1:40 pm, popy...@gmail.c om wrote:
>On May 19, 4:02 am, horacius....@gm ail.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.ex e.
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>
May 19 '07 #5
On May 19, 3:10 pm, "Barry" <bar...@nullhig hstream.netwrot e:
"Branimir Maksimovic" <b...@hotmail.c omwrote in message

news:11******** *************@k 79g2000hse.goog legroups.com...
On May 19, 1:40 pm, popy...@gmail.c om wrote:
On May 19, 4:02 am, horacius....@gm ail.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.ex e.
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.

May 19 '07 #6

<ho**********@g mail.comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.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.ex e.

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.

May 19 '07 #7
ho**********@gm ail.com 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
May 19 '07 #8
ho**********@gm ail.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.ex e.

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.
May 19 '07 #9
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
May 19 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
2942
by: Michael Strorm | last post by:
Hi! I posted a message a while back asking for project suggestions, and decided to go with the idea of creating an adventure game (although it was never intended to be a 'proper' game, rather an excuse to write- and learn- some C++). To cut a long story short, I wrote a fair chunk of it, but realised that it's... not very good. Okay, it's my first "proper" C++ program, so that's no big deal, but I don't want to waste more time working...
9
3462
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM, VARCHAR(10) WO.PROBLEMCODE, VARCHAR(8)
9
4244
by: adi | last post by:
Hi all, Hope there is a quick fix for this: I am inserting data from one table to another on the same DB. The insert is pretty simple as in: insert into datatable(field1, field2, field3) select a1, a2, a3 from temptable...
2
3161
by: terpatwork | last post by:
Hi, (1) I have an access form that allows users to enter data, and when they click a button, the OnClick code that I've written uses a SQL INSERT statement to insert the data into the database. I come from a web programming background, so please forgive me if there is some better approach to use in Access to accomplish this. My problem is that when users type in more than 512 characters (in a Memo field) and click the button, only the...
9
2406
by: zerro | last post by:
Hello, I try to understand heap overflows (under Linux), but can not understand one thing with freeing memory allocated with malloc(). Here it comes: I have a program called 1.c: main() { char *a, *b, *c, *d, *e; a = malloc(8);
4
3140
by: dragoncoder | last post by:
Hello all, I have the following code. Plesae have a look. #include <iostream> #include <string> #include <map> #include <cstdlib> using namespace std;
2
4188
by: mirandacascade | last post by:
O/S: Win2K Vsn of Python: 2.4 Example: <a> <b createAnotherWhenCondition="x"> <c>text for c</c> <d>text for d</d> </b>
15
395
by: horacius.rex | last post by:
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++.
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.