implicit-declaration

Implicit function declarations sometimes work in C?

浪子不回头ぞ 提交于 2019-12-01 12:00:00
Can someone please explain to me why the following compiles: int main() { int a = mymethod(0); } int mymethod(int b) { return b; } but this does not: int main() { mymethod(0); } void mymethod(int b) { return; } I thought that forward declarations were required in C/C++, yet here is a counterexample. How do implicit declarations work in C? I assume when you say that it does not work in the second code example, you mean that you get a compile time error. The reason is that when there is an implicit function declaration, it is assumed to take a fixed number of arguments, and return int . However,

Why does/did C allow implicit function and typeless variable declarations?

泄露秘密 提交于 2019-11-30 07:25:29
问题 Why is it sensible for a language to allow implicit declarations of functions and typeless variables? I get that C is old, but allowing to omit declarations and default to int() (or int in case of variables) doesn't seem so sane to me, even back then. So, why was it originally introduced? Was it ever really useful? Is it actually (still) used? Note: I realise that modern compilers give you warnings (depending on which flags you pass them), and you can suppress this feature. That's not the

Why does/did C allow implicit function and typeless variable declarations?

人走茶凉 提交于 2019-11-29 03:38:29
Why is it sensible for a language to allow implicit declarations of functions and typeless variables? I get that C is old, but allowing to omit declarations and default to int() (or int in case of variables) doesn't seem so sane to me, even back then. So, why was it originally introduced? Was it ever really useful? Is it actually (still) used? Note: I realise that modern compilers give you warnings (depending on which flags you pass them), and you can suppress this feature. That's not the question! Example: int main() { static bar = 7; // defaults to "int bar" return foo(bar); // defaults to a

Header for scanf_s function

浪尽此生 提交于 2019-11-28 10:35:36
While answering this question I compiled the code on Ideone and got this error implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration] Isn't stdio.h is the header for scanf_s ? scanf_s is Microsoft-specific. Header is stdio.h but not in GCC. Used to Read formatted data from the standard input stream. These versions of scanf, scanf_s, _scanf_l, wscanf, _wscanf_l have security enhancements Where as Ideone uses GCC because of this only you got undefined reference to scanf_s Mostly You can found this function in windows based compilers like Visual Studio 2008 and Microsoft

Why is the move constructor neither declared nor deleted with clang?

社会主义新天地 提交于 2019-11-28 06:29:04
Consider the following classes. struct with_copy { with_copy() = default; with_copy(with_copy const&) {} with_copy& operator=(with_copy const&) { return *this; } }; struct foo { with_copy c; std::unique_ptr<int> p; }; Does with_copy have a copy constructor? Yes. It was explicitly defined. Does with_copy have a move constructor? No. The explicit copy constructor prevents it from being generated. Does with_copy have a deleted move constructor? No. Not having a move constructor is not the same as having a deleted one. A deleted move constructor would make an attempt to move ill-formed instead of

Header for scanf_s function

陌路散爱 提交于 2019-11-27 03:41:21
问题 While answering this question I compiled the code on Ideone and got this error implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration] Isn't stdio.h is the header for scanf_s ? 回答1: scanf_s is Microsoft-specific. Header is stdio.h but not in GCC. Used to Read formatted data from the standard input stream. These versions of scanf, scanf_s, _scanf_l, wscanf, _wscanf_l have security enhancements Where as Ideone uses GCC because of this only you got undefined reference to

Why is the move constructor neither declared nor deleted with clang?

只愿长相守 提交于 2019-11-27 01:22:03
问题 Consider the following classes. struct with_copy { with_copy() = default; with_copy(with_copy const&) {} with_copy& operator=(with_copy const&) { return *this; } }; struct foo { with_copy c; std::unique_ptr<int> p; }; Does with_copy have a copy constructor? Yes. It was explicitly defined. Does with_copy have a move constructor? No. The explicit copy constructor prevents it from being generated. Does with_copy have a deleted move constructor? No. Not having a move constructor is not the same