两个'主'功能在C / C ++ [英] Two 'main' functions in C/C++

查看:151
本文介绍了两个'主'功能在C / C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在C或C写的程序与++两个主要的功能是什么?

Can I write a program in C or in C++ with two main functions?

推荐答案

没有。所有的程序有一个单一的main(),这是编译器和链接器生成启动一个可执行某处明智的。

No. All programs have a single main(), that's how the compiler and linker generate an executable that start somewhere sensible.

您基本上有两种选择:


  1. 有主()间preT一些命令行参数来决定叫什么实际的主力。其缺点是,你将有这两个程序的可执行文件。

  1. Have the main() interpret some command line arguments to decide what actual main to call. The drawback is that you are going to have an executable with both programs.

出的共享code的创建库和编译针对该库中的每个主文件。你会用两个可执行文件结束。

Create a library out of the shared code and compile each main file against that library. You'll end up with two executables.

这篇关于两个'主'功能在C / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆