hai all,
itz just a query,can i have two main function in a C program(1 file) 7 1919
"Rex" <me*******@gmail.com> wrote hai all, itz just a query,can I have two main function in a C program(1 file)
NO, because execution starts with main, and ANSI C programs are
single-threaded. Two mains would be ambiguous.
Quite often people need to write a temporary main, for instance to test
portions of code. Just change the name of the old main to "oldmain" and the
function will never be called.
Rex wrote on 13/08/04 : hai all, itz just a query,can i have two main function in a C program(1 file)
No. main() is just another function. You can't have 2 functions with
external linkage with the same name in a C program.
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool" me*******@gmail.com (Rex) wrote: itz just a query,can i have two main function in a C program(1 file)
Can you have two foo() functions in a single translation unit? Can you
have two bar() functions? No, and no. Why would main() be any different?
Richard
On Fri, 13 Aug 2004 08:41:21 +0200, Emmanuel Delahaye
<em***@YOURBRAnoos.fr> wrote in comp.lang.c: Rex wrote on 13/08/04 : hai all, itz just a query,can i have two main function in a C program(1 file)
No. main() is just another function. You can't have 2 functions with external linkage with the same name in a C program.
If they are both in one file (one translation unit), only one of them
needs to have external linkage. But that does not change the other
issue, you can't have two functions with the same name in a single
translation unit, regardless of linkage.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
No you can't have two.
The main function is the only function in your C code that will be execute.
I imagine that you want to execute two parts of your program (two process)
"at the same time" (i mean, in executing state). It is really simple in
linux but if you are in a windows platoform and in a C program it is not
posible.
Pablo.
"Rex" <me*******@gmail.com> wrote in message
news:f1**************************@posting.google.c om... hai all, itz just a query,can i have two main function in a C program(1 file)
Yes, there can be two main functions in a C program. Using preprocessor
directives, only one can be compiled during a single compilation (a/k/a
translation).
Paul
"Paul Heininger" <no****@nowhere.com> writes: "Rex" <me*******@gmail.com> wrote in message news:f1**************************@posting.google.c om... hai all, itz just a query,can i have two main function in a C program(1 file)
Yes, there can be two main functions in a C program. Using preprocessor directives, only one can be compiled during a single compilation (a/k/a translation).
Which means that, in effect, one of them doesn't exist.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Manuel |
last post by:
Can I invoke a function before main
I could do it by invoking it in a Global object's constructor .
Is there any other method other than this.
Manuel
|
by: Kwan Ting |
last post by:
The_Sage, I see you've gotten yourself a twin asking for program in
comp.lang.c++ .
http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1
If you the oh so mighty...
|
by: Steven T. Hatton |
last post by:
This is a purely *hypothetical* question. That means, it's /pretend/,
CP. ;-)
If you were forced at gunpoint to put all your code in classes, rather than
in namespace scope (obviously classes...
|
by: wongjoekmeu |
last post by:
Hello All,
>From a book where I have learned C++ it says that each application must
have at least one
function which is the main() function. Now I have the source code of a
C++ program from...
|
by: Stephen Mayes |
last post by:
Correct me if I am mistaken.
The C standard guarantees that in a C hosted environment we can define main
as:
int main( int argc, char *argv ).
I always assume that 'argc' is the number of...
|
by: Seong-Kook Shin |
last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version,
and have two question regarding to Q11.16
... Also, a `return' from `main' cannot be expected to work if
data local to main might be...
|
by: Michal Nazarewicz |
last post by:
Hi,
What does returning 0 from main() mean according to C89/C90 standard?
I've found that in C99 it means successful termination (7.20.4.3p5)
however as I'm editing book on C at Polish Wikibooks...
|
by: ravi |
last post by:
Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
|
by: aarklon |
last post by:
Hi all,
I have heard many discussions among my colleagues that main is a user
defined function or not.
arguments in favour:-
1) if it is built in function it must be defined in some header...
|
by: mike-yue |
last post by:
and, Is it possible to call one main function from another main
function?
Thanks guys.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |