void

Why cast unused return values to void?

≯℡__Kan透↙ 提交于 2019-11-25 23:30:26
问题 int fn(); void whatever() { (void) fn(); } Is there any reason for casting an unused return value to void, or am I right in thinking it\'s a complete waste of time? Follow up: Well that seems pretty comprehensive. I suppose it\'s better than commenting an unused return value since self documenting code is better than comments. Personally, I\'ll turn these warnings off since it\'s unnecessary noise. I\'ll eat my words if a bug escapes because of it... 回答1: David's answer pretty much covers the

Is it better to use C void arguments “void foo(void)” or not “void foo()”? [duplicate]

戏子无情 提交于 2019-11-25 22:44:42
问题 This question already has an answer here: Is there a difference between foo(void) and foo() in C++ or C? 4 answers func() vs func(void) in c99 4 answers What is better: void foo() or void foo(void) ? With void it looks ugly and inconsistent, but I\'ve been told that it is good. Is this true? Edit: I know some old compilers do weird things, but if I\'m using just GCC, is void foo() Ok? Will foo(bar); then be accepted? 回答1: void foo(void); That is the correct way to say "no parameters" in C,

What does “Incompatible types: void cannot be converted to …” mean?

限于喜欢 提交于 2019-11-25 22:23:22
问题 What does the Java compilation message: \"Incompatible types: void cannot be converted to ...\" mean, and how do I fix it. Some compilers use different wording; e.g. \"Type mismatch: cannot convert from void to ...\" or \"Incompatible types. Required: ... Found: void (This is intended to be a canonical Q&A for a very specific compilation error message involving \"void\" that confuses new Java programmers. It is not intended to be a tutorial on the various different \"type conversion\"

What does “javascript:void(0)” mean?

别说谁变了你拦得住时间么 提交于 2019-11-25 22:20:14
问题 <a href=\"javascript:void(0)\" id=\"loginlink\">login</a> I\'ve seen such href s many times, but I don\'t know what exactly that means. 回答1: The void operator evaluates the given expression and then returns undefined . The void operator is often used merely to obtain the undefined primitive value, usually using “ void(0) ” (which is equivalent to “ void 0 ”). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value). An