473,378 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Calling 'foo.c' or 'foo2.c' from my 'main_code.c'

Hello.

I don't know if following is possible.

I've got 'main_code.c':
............................
char * another_code;
another_code = "foo.c";
............................

I've got 'foo.c':
............................
#include <stdio.h>
int main()
{
printf ("Hello world from 'foo.c'!\n");
return 0;
}
............................

I would like to call 'foo.c' main function from 'main_code.c'.

Is this possible?

Thank you very much and best regards.
Nov 14 '05 #1
4 1103
Francesco Moi <fr**********@europe.com> scribbled the following:
Hello. I don't know if following is possible. I've got 'main_code.c':
...........................
char * another_code;
another_code = "foo.c";
........................... I've got 'foo.c':
...........................
#include <stdio.h>
int main()
{
printf ("Hello world from 'foo.c'!\n");
return 0;
}
........................... I would like to call 'foo.c' main function from 'main_code.c'. Is this possible? Thank you very much and best regards.


If you link the object files compiled from main_code.c and foo.c
together, all you have to do is call main(). Otherwise, if they are
linked into separate executables, you essentially have to use
system() to call the other executable via the OS. This will, of
course, require using the name of the executable, not of its source.
If you want to call a specific function (not necessarily main()),
you can try to find a system-specific IPC (Inter-Process Communication)
feature from your OS, or implement a C interpreter.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You can pick your friends, you can pick your nose, but you can't pick your
relatives."
- MAD Magazine
Nov 14 '05 #2

"Francesco Moi" <fr**********@europe.com> wrote in message

I don't know if following is possible.

I've got 'main_code.c':

I would like to call 'foo.c' main function from 'main_code.c'.

Not in standard ANSI C. Only one main() function is allowed which is the
program start point. You need to rename the "main" in foo.c as something
else (eg foomain).
Nov 14 '05 #3
Malcolm <ma*****@55bank.freeserve.co.uk> spoke thus:
Not in standard ANSI C. Only one main() function is allowed which is the
program start point. You need to rename the "main" in foo.c as something
else (eg foomain).


Is it correct to say that your statements apply to hosted
implementations only?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #4

"Christopher Benson-Manica" <at***@nospam.cyberspace.org>

Is it correct to say that your statements apply to hosted
implementations only?

A non-hosted implementation may have a start point other than main(). It may
even allow main() as a normal function name, so you could link in foo.c with
a main(), once, when you try to link bar.c with it's main() you're back to
square one.
Nov 14 '05 #5

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

Similar topics

7
by: Alex Vinokur | last post by:
========================================== Windows 2000 Professional CYGWIN_NT-5.0 1.5.4(0.94/3/2) GNU g++ version 3.2 20020927 (prerelease) GNU objdump 2.14.90 20030901...
3
by: Dave McCracken | last post by:
I am hosting .Net UserControls in HTML pages with Object Tags. These UserControls are clients of remotable objects that run on the same machine. The remote objects execute callbacks via sponsor...
3
by: scott | last post by:
hi all, hope some one can help me. Ill try and explain what im trying to do as best i can. i have a parent class that has a vertual function, lets call it virtual int A(). That vertual function...
4
by: Alex Vinokur | last post by:
Why is it ambiguous? ------ foo.cpp ------ struct Foo { Foo operator* (Foo) { return Foo(); } Foo operator* (int) const { return Foo(); } Foo () {} Foo (int) {} };
2
by: GB | last post by:
Is there a way to call a function from a string instead of calling the function explictly? For example: dim fooStr as string fooStr = "foo1" ' The question:
1
by: Andrew | last post by:
Hi there, I'm trying to find out what is causing this error: <faultstring>Procedure 'foo' not present</faultstring> I've got a class 'bar' with a public function 'foo'. I create a...
8
by: Alex Vinokur | last post by:
Microsoft C++ Version 13.10.3077 Why is virtual function init() called in constructor here? ====== foo.cpp ====== #include "iostream" using namespace std; class Base {
2
by: Brian | last post by:
I just have a basic style question here. Suppose you have the program: def foo1(): do something def foo2() do something else Assume that you want to call these functions at execution. Is...
1
by: newbie | last post by:
This is a snippet from C++ FAQs, which I have never done--- when I do such a thing, I would declare function used by constructor ( in this example, init() ) as static. But I do understand that it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.