Questions tagged [function-declaration]

A function declaration is the process of describing only the return type, argument types, and name of a function. This is required in some programming languages to use functions that were defined at a later point in the code or in another file. Use this tag for questions that pertain to or problems caused by forward declaring functions in languages that support or require doing so.

549 questions
4
votes
4 answers

Javascript: how much more efficient is forked function declaration?

I just read through this article on named function expressions and their incompatibilities with IE <= 8. I'm curious about one statement in particular: A common pattern in web development is to “fork” function definitions based on some kind of a…
Eric Hu
  • 18,048
  • 9
  • 51
  • 67
4
votes
3 answers

How to find out if a function has been declared by `lambda` or `def`?

If I declare two functions a and b: def a(x): return x**2 b = lambda x: x**2 I can not use type to differentiate them, since they're both of the same type. assert type(a) == type(b) Also, types.LambdaType doesn't help: >>> import types >>>…
finefoot
  • 9,914
  • 7
  • 59
  • 102
4
votes
4 answers

Declaring function inside function in C

I found this question on an online exam. This is the code: #include int main(void) { int demo(); demo(); (*demo)(); return 0; } int demo(){ printf("Morning"); } I saw the answer after the test. This is the…
Debanik Dawn
  • 797
  • 5
  • 28
4
votes
1 answer

What is the role of this macro in function declaration?

I have downloaded some library and it declares the functions the following way: #if !defined(__ANSI_PROTO) #if defined(_WIN32) || defined(__STDC__) || defined(__cplusplus) # define __ANSI_PROTO(x) x #else # define __ANSI_PROTO(x) …
4
votes
2 answers

Nested `constexpr` function calls before definition in a constant-expression context

From what I gather from this answer, a constexpr function's result is not a constant-expression if the function has not been declared yet. What surprises me is the following code snippet : constexpr int f(); constexpr int g() { return…
4
votes
2 answers

Function declaration with string message

I'm getting an "Error: 'message' was not declared in this scope" error for the declaration of the int getValue function when compiling. This function is supposed to take user inputted integers and deliver them to the main function. Have I…
0x100001
  • 55
  • 4
4
votes
3 answers

Why is a 'conflicting type' error being thrown when I execute this program?

In K&R Chapter 1.9, I've been experimenting with the program provided below. Particularly, what would happen if I removed certain decelerations of functions. So, I removed line #4. int getline(char line[], int maxline And the program complies…
Jaccob
  • 51
  • 1
4
votes
4 answers

Implicit function declarations and linkage

Recently I've learnt about implicit function declarations in C. The main idea is clear but I have some troubles with understanding of the linkage process in this case. Consider the following code ( file a.c): #include int main() { …
Edgar Rokjān
  • 17,245
  • 4
  • 40
  • 67
4
votes
3 answers

why MSVS allows NULL as pure virtual function specifier?

Consider following program: struct Test { virtual void foo()=NULL; }; int main() { } g++ 4.8.1 gives an expected error as following: [Error] invalid pure specifier (only '= 0' is allowed) before ';' token Clang gives following error: error:…
Destructor
  • 14,123
  • 11
  • 61
  • 126
4
votes
3 answers

In JavaScript, why can't I immediately invoke function declarations?

Only functions expressions can be immediately invoked: (function () { var x = "Hello!!"; // I will invoke myself })(); But not function declarations? Is this because function declarations are hoisted and already execute immediately? EDIT:…
4
votes
2 answers

Example of function prototype scope

There is a definition of function prototype scope (3.3.4/1 N3797): In a function declaration, or in any function declarator except the declarator of a function definition (8.4), names of parameters (if supplied) have function prototype scope,…
user2953119
4
votes
1 answer

Most vexing parse: why doesn't `g( ( f() ) );` call `f`'s default constructor and pass the result to `g`'s ctor that takes a `f`?

This isn't a duplicate of Most vexing parse: why doesn't A a(()); work?, which is based on a parse in the form of A a(());, whose OP thought would be able to default-construct an A object using the extra set of parentheses. In contrast, my question…
CodeBricks
  • 1,771
  • 3
  • 17
  • 37
4
votes
6 answers

Why include header in the method definition file?

say you have a source file named sum.c that looks like this: #include "sum.h" int sum(int x, int y) { return x+y; } What's the point of including method's header in it's own definition file? Aren't you supposed to include it only in source…
Daar
  • 3,385
  • 4
  • 20
  • 18
4
votes
1 answer

The Stepdown Rule in Clean Code

There is something about the Stepdown Rule (high level function at top and low level next) in clean code (Chapter 3, One Level of Abstraction per Function ). What should I do when I use coffeescript since there is no function declarations in…
user2666750
  • 582
  • 1
  • 7
  • 11
4
votes
3 answers

When using PInvoke, why use __stdcall?

I have been using PInvoke to let my C# application call C++ functions I wrote. Now, I keep hearing everywhere and beyond that I need to define those externally accessible functions with the __stdcall convention. My question is: Why? So far, I have…
Lee White
  • 3,649
  • 8
  • 37
  • 62