can u do a c++ program without main function.....?

Recommended Answers

All 10 Replies

No u can't do a program without main function.When u compile the program u will not get any error message.But when u run the program the compiler will serach for the main function to be executed first.At that time u will get a error message.As your program may contain many functions the compiler will first search for the main function inorder to avoid the confusion as which function must be called first.

Hi,

see like C programs ,execution of all C++ programs begins at main()function and ends at the return statement.

Structure of C++ program is as follows:

INCLUDE FILES
    CLASS DECLARATION
    MEMBER FUNCTION DECLARATION
    MAIN FUNCTION PROGRAM

so you can not write a c++ proram with out main function. clear your basic
<<plug removed>>


Thanks
Kolla Sanjeeva rao

>can u do a c++ program without main function.....?
It's splitting hairs, but yes, you can if your compiler supports alternative entry points. For example, Microsoft's CL compiler supports WinMain as an entry point instead of main.

GCC's linker supports alternate entry point names

ld - The GNU linker

-e entry
--entry=entry
Use entry as the explicit symbol for beginning execution of your
program, rather than the default entry point. If there is no
symbol named entry, the linker will try to parse entry as a number,
and use that as the entry address (the number will be interpreted
in base 10; you may use a leading 0x for base 16, or a leading 0
for base 8).

Use code tags

<<snip>>

Use code tags

It was spam anyway.

It was spam anyway.

I don't get it. The program worked fine with me, and it's got no main().

I hadn't actually tried to compile it, but it does use some preprocessor directives to change the InfernoDevelopment() into main(). So, there is still a main() once the program compiles, it's just obfuscated in the source, so bravo to pradeep. However, this could have been 100x better if he/she offered some explanation and wasn't shamelessly self promoting.

yeah, an explanation would have helped.

And it also got deleted.

Do not mention, plug or refer to any product, service, or website you are affiliated with anywhere outside of Business Exchange forums specifically designated for this purpose

:)

commented: Thanks Santa! +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.