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.
Questions tagged [function-declaration]
549 questions
                    
                    226
                    
            votes
                
                9 answers
            
        Is it possible to define more than one function per file in MATLAB, and access them from outside that file?
When I was studying for my undergraduate degree in EE, MATLAB required each function to be defined in its own file, even if it was a one-liner.
I'm studying for a graduate degree now, and I have to write a project in MATLAB. Is this still a…
         
    
    
        Nathan Fellman
        
- 122,701
- 101
- 260
- 319
                    89
                    
            votes
                
                5 answers
            
        What's the significance of a C function declaration in parentheses apparently forever calling itself?
In gatomic.c of glib there are several function declarations that look like this:
gboolean
(g_atomic_int_compare_and_exchange_full) (gint *atomic,
                                          gint  oldval,
                                          gint…
         
    
    
        Andreas
        
- 9,245
- 9
- 49
- 97
                    88
                    
            votes
                
                4 answers
            
        JavaScript function declaration and evaluation order
Why does the first one of these examples not work, but all the other ones do?
// 1 - does not work
(function() {
setTimeout(someFunction1, 10);
var someFunction1 = function() { alert('here1'); };
})();
// 2
(function() {
setTimeout(someFunction2,…
         
    
    
        We Are All Monica
        
- 13,000
- 8
- 46
- 72
                    87
                    
            votes
                
                3 answers
            
        How to provide explicit type declarations for functions when using GHCi?
How to I define the equivalent of this function (taken from learnyouahaskell) inside GHCi?
import Data.List  
numUniques :: (Eq a) => [a] -> Int  
numUniques = length . nub  
Without the type declaration, GHCi accepts the function definition, but…
         
    
    
        mattbh
        
- 5,230
- 2
- 27
- 27
                    86
                    
            votes
                
                6 answers
            
        Alternative (K&R) C syntax for function declaration versus prototypes
What is useful about this C syntax — using 'K&R' style function declarations?
int func (p, p2)
    void* p;
    int  p2;
{
    return 0;
}
I was able to write this in Visual Studios 2010beta
// yes, the arguments are flipped
void f()
{
    void* v…
        user34537
                    83
                    
            votes
                
                11 answers
            
        Why can't I define a function inside another function?
This is not a lambda function question, I know that I can assign a lambda to a variable.
What's the point of allowing us to declare, but not define a function inside code?
For example:
#include 
int main()
{
    // This is illegal
    //… 
         
    
    
        Jonathan Mee
        
- 37,899
- 23
- 129
- 288
                    80
                    
            votes
                
                7 answers
            
        Function declaration in CoffeeScript
I notice that in CoffeeScript, if I define a function using:
a = (c) -> c=1
I can only get the function expression:
var a;
a = function(c) {
    return c = 1;
};
But, personally I often use function declaration,for example:
function a(c) {
   …
         
    
    
        Grace Huang
        
- 5,355
- 5
- 30
- 52
                    66
                    
            votes
                
                7 answers
            
        Does int main() need a declaration on C++?
I was taught that functions need declarations to be called. To illustrate, the following example would give me an error as there is no declaration for the function sum:
#include 
int main() {
  std::cout << "The result is " << sum(1, 2);
… 
         
    
    
        vinibrsl
        
- 6,563
- 4
- 31
- 44
                    65
                    
            votes
                
                3 answers
            
        Whyever **not** declare a function to be `constexpr`?
Any function that consists of a return statement only could be declared
constexpr and thus will allow to be evaluated at compile time if all
arguments are constexpr and only constexpr functions are called in its body. Is there any reason not to…
         
    
    
        Lars
        
- 2,616
- 3
- 21
- 18
                    46
                    
            votes
                
                2 answers
            
        Function default argument value depending on argument name in C++
If one defines a new variable in C++, then the name of the variable can be used in the initialization expression, for example:
int x = sizeof(x);
And what about default value of a function argument? Is it allowed there to reference the argument by…
         
    
    
        Fedor
        
- 17,146
- 13
- 40
- 131
                    38
                    
            votes
                
                4 answers
            
        Maximum number of parameters in function declaration
I know that minimum number of parameters in function definition is zero, but what is the maximum number of parameters in function definition? I am asking the question just for the sake of knowledge and out of curiosity, not that I am going to write…
         
    
    
        Nawaz
        
- 353,942
- 115
- 666
- 851
                    37
                    
            votes
                
                2 answers
            
        Can a function prototype typedef be used in function definitions?
I have a series of functions with the same prototype, say
int func1(int a, int b) {
  // ...
}
int func2(int a, int b) {
  // ...
}
// ...
Now, I want to simplify their definition and declaration. Of course I could use a macro like that:
#define…
         
    
    
        bitmask
        
- 32,434
- 14
- 99
- 159
                    28
                    
            votes
                
                3 answers
            
        How does ampersand in the return type of a function declaration work?
In this piece of code, why f() is declared as "double & f(..."? What does it mean and how does it work? I don't even know what to google to find the answer to my question. Please help.
double a = 1, b = 2;
double & f (double & d) {
    d = 4;
   …
         
    
    
        Azad Salahli
        
- 876
- 3
- 14
- 30
                    27
                    
            votes
                
                3 answers
            
        Function pointer parameter without asterisk
I have seen this definition of a function that receives a function pointer as parameter:
double fin_diff(double f(double), double x, double h  = 0.01) {
  return (f(x+h)-f(x)) / h;
}
I am used to see this definition with an asterisk, i.e.:
double…
         
    
    
        Freeman
        
- 5,810
- 3
- 47
- 48
                    27
                    
            votes
                
                8 answers
            
        JavaScript function declaration
Are the JavaScript code snippets given below some sort of function declaration? If not can someone please give an overview of what they are?
some_func = function(value) {
    // some code here
}
and
show:function(value){
   // some code here
}
         
    
    
        Anand Shah
        
- 14,575
- 16
- 72
- 110