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
5
votes
4 answers

Strange behavior of float in function definition. And declaration-definition mismatch, yet it works, how?

How does the following code work even though the signature of the function in the declaration doesn't match with the definition? The function declaration has empty parameter list, yet the definition has one parameter. Why the compiler doesn't give…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
5
votes
1 answer

How to declare function pointer parameter

What is the difference between these 2 declarations: double math_operation(double x, double (*func)(double)); double math_operation(double x, double func(double)); They both seem to work with the same exact call in GCC: math_operation(2.0,…
DarkAtom
  • 2,589
  • 1
  • 11
  • 27
5
votes
5 answers

difference between (a -> a) and a -> a

I've noticed that (although I was once told that (a -> a) and a -> a meant the same thing), I get error messages when I use the (a -> a). Should I only use (a -> a) when using brackets amongst the types? (i.e. (5 + 3) instead of 5 + 3)? Just not…
maclunian
  • 7,893
  • 10
  • 37
  • 45
5
votes
2 answers

What does '->' mean in a function declaration in Python 3?

Recently, I have come across this -> in Python 3 when studying function declarations. What does this do and mean? I have never seen such a declaration other than in a Javascript function declaration up until now. def f(self, s: 'str') -> 'bool': …
Seungho Lee
  • 1,068
  • 4
  • 16
  • 42
5
votes
3 answers

Function "normalization"

Here's a concept from the DB normalization theory: Third normal form is violated when a non-key field is a fact about another non-key field. Doesn't it makes sense for a similar concept be applied for functions / function parameters? Consider the…
Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201
5
votes
1 answer

Weird C function declaration

I was going through some code when I encountered this in one of the source files. int st_insert(table, key, value) register st_table *table; register st_data_t key; st_data_t value; { unsigned int hash_val, bin_pos; register st_table_entry…
calccrypto
  • 8,583
  • 21
  • 68
  • 99
5
votes
0 answers

gcc: using declaration at namespace scope shadows overload

I have a strange problem with gcc 5.1.0. The following minimal code // header 1 namespace A { template inline constexpr X square(X x) { return x*x; } } // header 2 namespace A { namespace B { template struct…
Walter
  • 44,150
  • 20
  • 113
  • 196
5
votes
2 answers

Is there an intention behind the auto keyword in trailing return type function syntax?

In C++11, the two lines are equivalent. From what I see, the the advantage of the second syntax is that the return type is in class scope. Therefore, you can use both, nested types of the class directly and decltype expressions of non static…
danijar
  • 32,406
  • 45
  • 166
  • 297
5
votes
3 answers

Should int a, f() {} compile?

for a typo, I leave the a in there. When I went to compile, the compiler reported: missing a ',' between declaration of 'a' and 'f' code: int a f(void) { } And was very surpresing since I've never get any error message like this and I didn't…
Jack
  • 16,276
  • 55
  • 159
  • 284
5
votes
1 answer

Function Declaration vs Function Expression in the Module Pattern

I have just learned about the difference between Function Declarations and Function Expressions. This got me wondering about whether or not I'm doing things right in my AngularJS code. I'm following the pattern used by John Papa, but now it seems at…
5
votes
0 answers

Should the trailing return type syntax be the default syntax for all functions?

Possible Duplicate: alternative function syntax In complicated function templates, you sometimes need the C++11 trailing return type syntax in order to use decltype on parameters, which otherwise would come into scope too late: template
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
4
votes
6 answers

C++ void function declarations

Possible Duplicate: C++ Why put void in params? What's the difference between these two declarations and which is used more commonly? void function1(); and void function2( void );
lorenzoid
  • 1,812
  • 10
  • 33
  • 51
4
votes
5 answers

Understanding how to use typedef void function with pointers as params

I'm trying to understand a firmware written in C that drives a chip for ultrawideband connections. The firmware does heavy use of typedef and pointers. I've understood most of the idea behind the firmware but there's a typedef void function I can't…
NicoCaldo
  • 1,171
  • 13
  • 25
4
votes
2 answers

Variable looks like a function pointer

char *getoccupier(int roomno) { //... } int main() { int j; char *getoccupier(int), *p; for (j = 1; j <= NROOMS; j++) { if (p == getoccupier(j)) { //... } } } In the main function I…
evergreen
  • 681
  • 10
  • 22
4
votes
2 answers

Function Pointer Declaration

I'm a little confused by the textbook I'm using compared to examples, SO answers, and tutorials I've found online. The code from the book declares two function pointers but never assigns a value to them, and it doesn't use * in the declaration. The…