主要是()A pre-定义的C函数? [英] Is main() a pre-defined function in C?

查看:212
本文介绍了主要是()A pre-定义的C函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  的main()在C,C ++,Java和C#

我在一般新的节目,和C中尤其如此。我看有一个主功能每个实例 - 这是$ P $以某种方式对定义,这样的名字呈现出特殊意义的编译器或运行时......还是仅仅是一个常见的​​成语C程序员之间(比如使用foo和酒吧任意变量名)。

I'm new to programming in general, and C in particular. Every example I've looked at has a "main" function - is this pre-defined in some way, such that the name takes on a special meaning to the compiler or runtime... or is it merely a common idiom among C programmers (like using "foo" and "bar" for arbitrary variable names).

推荐答案

没有,您需要定义在你的程序。由于它是由运行时调用,但是,接口的必须提供为pre定义(必须返回 INT ,必须采取零个参数或两个,第一个 INT ,第二一个的char ** 或等价地,的char * [] )。 C和C ++标准并指定具有外部链接的功能,名为充当入口点计划 1

No, you need to define main in your program. Since it's called from the run-time, however, the interface your main must provide is pre-defined (must return an int, must take either zero arguments or two, the first an int, and the second a char ** or, equivalently, char *[]). The C and C++ standards do specify that a function with external linkage named main acts as the entry point for a program1.

目前至少与期限一般使用时,predefined功能将是诸如的printf 这是标准库,所以你可以使用它,而不必自己动手写。

At least as the term is normally used, a predefined function would be one such as sin or printf that's in the standard library so you can use it without having to write it yourself.

1 如果你想获得的技术,这是唯一真正的托管的实施 - 即那种我们大多数人使用最多的产生,一个操作系统上运行的程序的时候。 A自立的实施(一个产生直接在裸机下它没有操作系统运行程序)是免费的,因为它认为合适的定义的入口点(S)。一项独立的实现也可以离开了最正常的运行时库,只提供头极少数(如< STDDEF.H> ),几乎没有标准库函数。

1If you want to get technical, that's only true for a "hosted" implementation -- i.e., the kind most of us use most of the time that produces programs that run on an operating system. A "free-standing" implementation (one produces program that run directly on the "bare metal" with no operating system under it) is free to define the entry point(s) as it sees fit. A free-standing implementation can also leave out most of the normal run-time library, providing only a handful of headers (e.g., <stddef.h>) and virtually no standard library functions.

这篇关于主要是()A pre-定义的C函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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