473,385 Members | 1,531 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,385 software developers and data experts.

how can we have two main function

Dear All,
As all know C does not support Polymorphism concept. And we can't declare two function with same name then how we can have two main function
for ex
main ();
or

main (argv,argc[])
then how it is possible. Even printf is also work in the same concept. Printf is a function which can take multiple parameter and that too different parameter

Can you help me in this....
Mar 2 '08 #1
2 2287
gpraghuram
1,275 Expert 1GB
Dear All,
As all know C does not support Polymorphism concept. And we can't declare two function with same name then how we can have two main function
for ex
main ();
or

main (argv,argc[])
then how it is possible. Even printf is also work in the same concept. Printf is a function which can take multiple parameter and that too different parameter

Can you help me in this....


printf declartion is
int printf(char *args,...);
So you can pass anything in the args string.
This is not overloading.
printf is use of variable argument list.
You can go for 2 mains if you can put the main in #ifdef and supply the variable using -D while compiling the code

Raghuram
Mar 3 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
As all know C does not support Polymorphism concept.
It does if you use function pointers in your structs. It's just that C++ makes it easy whereas in C you have to do a lot more work. B ut I have seen polymorphic C programs in operation.

Setting up a VTBL is just not that hard.
Mar 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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
192
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...
45
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...
4
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...
16
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...
5
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...
8
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...
28
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,
11
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...
17
by: mike-yue | last post by:
and, Is it possible to call one main function from another main function? Thanks guys.
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
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...
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.