Which one to use when static

Possible Duplicate: Should I use static_cast or reinterpret_cast when casting a void* to whatever Often, especially in Win32 programming it is required to cast from one opaque type to another. For example: HFONT font = cast_here<HFONT>( ::GetStockObject( SYSTEM_FONT ) ); Both static_cast and reinterpret_cast are applicable here and have exactly the same effect since HFONT is a point

静态时使用哪一个

可能重复: 在将void *转换为任何内容时,我应该使用static_cast还是reinterpret_cast 通常,特别是在Win32编程中,它需要从一种不透明类型转换为另一种类型。 例如: HFONT font = cast_here<HFONT>( ::GetStockObject( SYSTEM_FONT ) ); static_cast和reinterpret_cast在这里都适用,并且具有完全相同的效果,因为HFONT是一个指向专门用于定义由GetStockObject()返回的HFONT和HGDIOBJ的虚拟结构体的指针,它是

What was the rationale for making `return 0` at the end of `main` optional?

Starting with the C99 standard, the compiler is required to generate the equivalent of a return 0 or return EXIT_SUCCESS if no return is supplied at the end of main . There was also a corresponding and identical change to the C++ language standard around that same time. I am interested in the reasons for both and I guessed that it was unlikely they were entirely separate and unrelated changes.

在`main`选项末尾做'return 0`的原因是什么?

从C99标准开始,编译器需要生成等价的return 0或return EXIT_SUCCESS如果在main的末尾没有提供返回值。 大约在同一时间,C ++语言标准也出现了相应的变化。 我对两者的理由感兴趣,我猜想这不可能是完全独立和无关的变化。 我的问题是: 记录这个变化的理由是什么? 一个理想的答案会引用C和C ++的权威来源,这就是为什么我用两种语言标记问题的原因。 请注意,与问题不同的是,在ISO C ++中主要返回0的原因是什么?我

What the reasons for/against returning 0 from main in ISO C++?

I know that the C++ standard says that return 0 is inserted at the end of main() if no return statement is given; however, I often see recently-written, standard-conforming C++ code that explicitly returns 0 at the end of main() . For what reasons would somebody want to explicitly return 0 if it's automatically done by the compiler? 因为从具有非无效返回类型的函数中“返回”某些东西(即使标准

在ISO C ++中从main返回0的原因是什么?

我知道C ++标准说如果没有返回语句, return 0被插入到main()的末尾; 然而,我经常看到最近编写的符合标准的C ++代码,它们在main()的末尾显式返回0。 如果由编译器自动完成,那么有人希望显式返回0的原因是什么? 因为从具有非无效返回类型的函数中“返回”某些东西(即使标准说它不是绝对必要的),它看起来很奇怪。 通过明确你明确地表明你的意图。 依靠隐含的东西,你可能会有两种情况:1)你打算这样做,2)你忘了它。

Legal definitions of main() in C++14

The last draft of C++14 that I was able to find says, regarding main() [3.6.1]: An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined. All implementations shall allow both — a function of () returning int and — a function of (int, pointer to pointer to char)

main()在C ++中的法律定义14

我能找到的C ++ 14的最后一份草稿说,关于main() [3.6.1]: 一个实现不应该预定义主函数。 该功能不得超载。 它应该有一个类型为int的返回类型,否则它的类型是实现定义的。 所有的实现应该允许两者 - ()返回int和的函数 - (int,指向指向char的指针)返回int的函数 和(第5段) 如果控制到达主的结尾而没有遇到return语句,则效果是执行 return 0; 这是否意味着以下所有内容都是合法的C ++ 14最低程序?

Why does int main() {} compile?

(I'm using Visual C++ 2008) I've always heard that main() is required to return an integer, but here I didn't put in return 0; and and it compiled with 0 errors and 0 warnings! In the debug window it says the program has exited with code 0. If this function is named anything other than main(), the compiler complains saying 'blah' must return a value. Sticking a return; als

为什么int main(){}编译?

(我使用的是Visual C ++ 2008)我总是听说main()需要返回一个整数,但是在这里我没有把return 0;作为return 0; 并编译了0个错误和0个警告! 在调试窗口中,它表示程序已退出代码0.如果此函数的名称不是main(),则编译器会抱怨说'blah'必须返回一个值。 坚持return; 也会导致错误出现。 但完全放弃它,它编译得很好。 #include <iostream> using namespace std; int main() { cout << "Hey lo

Why is the type of the main function in C and c++ left to the user to define?

This question already has an answer here: What should main() return in C and C++? 19 answers EDIT This answer is not as complete as it could be since it doesn't really address the strange sentence "or otherwise in some implementation-defined manner". I have now written a more complete answer which also addresses C90, C11 and C++. END OF EDIT Here is what the C standard says

为什么C和c ++中的主要函数的类型留给用户去定义?

这个问题在这里已经有了答案: main()应该在C和C ++中返回什么? 19个答案 编辑这个答案并不完整,因为它没有真正解决奇怪的句子“或以某种实现定义的方式”。 我现在写了一个更完整的答案,这也解决了C90,C11和C ++。 编辑结束 这是C标准所说的(ISO C 9899:1999): 5.1.2.1独立环境 在一个独立的环境中(C程序的执行可能没有任何操作系统的好处),程序启动时调用的函数的名称和类型是实现定义的。 / .. /独

Must the int main() function return a value in all compilers?

This question already has an answer here: What should main() return in C and C++? 19 answers 在C ++中,在C99和C11中,如果控制流到达main函数的末尾,则语言的特殊规则是,函数impliclty返回0 。 In C++ and C99/C11, without a return statement in main function, it's default to return 0 ; § 3.6.1 Main function A return statement in main has the effect of leaving the main function (destroying

int main()函数是否必须在所有编译器中返回一个值?

这个问题在这里已经有了答案: main()应该在C和C ++中返回什么? 19个答案 在C ++中,在C99和C11中,如果控制流到达main函数的末尾,则语言的特殊规则是,函数impliclty返回0 。 在C ++和C99 / C11中,在main函数中没有返回语句,它默认返回0 ; §3.6.1主要功能 main中的return语句具有离开main函数(销毁具有自动存储持续时间的任何对象)并以返回值作为参数调用std :: exit的效果。 如果控制到达main的结尾而没有遇

int main(int argc, char *argv[])

If I have this: int main(int argc, char *argv[]) In the body, you can sometimes find programs using argv[1] . When do we use argv[1] over argv[0] ? Is it only when we just want to read the second argument in the command line? By convention , argv[0] is the current program's name (or path), and argv[1] through argv[argc - 1] are the command-line arguments that the user provides. Howev

int main(int argc,char * argv [])

如果我有这个: int main(int argc, char *argv[]) 在本体中,有时可以使用argv[1]找到程序。 我们什么时候在argv[0]使用argv[1] argv[0] ? 仅当我们想要读取命令行中的第二个参数时才这样做? 按照惯例 , argv[0]是当前程序的名称 (或路径), argv[1]至argv[argc - 1]是用户提供的命令行参数 。 但是,这并非必须如此 - 程序可以通过操作系统特定的功能绕过这一要求,而且这种情况经常发生,以至于您应该意识到这

int main(int argc, char** argv)

Possible Duplicate: What is the proper declaration of main? What do we mean by the arguments in this main function? What are they trying to tell us? int main(int argc, char** argv) UPDATE: And, is the preceding line of code similar to this int main(int argc, char* argv[]) ? If so, how can we say that char** argv is similar to char* argv[] as they don't look similar from an array poi

int main(int argc,char ** argv)

可能重复: 什么是正确的主要声明? 这个main函数中的参数意味着什么? 他们想告诉我们什么? int main(int argc, char** argv) 更新:而且,前面的代码行类似于这个int main(int argc, char* argv[]) ? 如果是这样,我们怎么能说char** argv类似于char* argv[]因为它们与数组的角度看起来不相似? 它与int main()没有任何参数相比如何? 谢谢。 argc参数是在调用可执行文件时指定的命令行选项的数量,包括可执

What is the proper declaration of main?

What is the proper signature of the main function in C++? What is the correct return type, and what does it mean to return a value from main ? What are the allowed parameter types, and what are their meanings? Is this system-specific? Have those rules changed over time? What happens if I violate them? The main function must be declared as a non-member function in the global namespace. Th

什么是正确的主要声明?

什么是C ++中main函数的正确签名? 什么是正确的返回类型,从main返回一个值意味着什么? 什么是允许的参数类型,它们的含义是什么? 这是系统特定的吗? 这些规则是否随着时间而改变? 如果我违反了他们会怎么样? main函数必须在全局名称空间中声明为非成员函数。 这意味着它不能是类的静态或非静态成员函数,也不能放置在命名空间(即使是未命名的命名空间)中。 除了作为全局名称空间中的函数之外,名称main不保