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

Why can't a typedef of a function be used to define a function?

From § 8.3.5.11 of ISO/IEC 14882:2011(E): A typedef of function type may be used to declare a function but shall not be used to define a function The standard goes on to give this example: typedef void F(); F fv; // OK: equivalent to void fv(); F…
Shea Levy
  • 5,237
  • 3
  • 31
  • 42
12
votes
5 answers

extern declaration and function definition both in the same file

I was just browsing through gcc source files. In gcc.c, I found something like extern int main (int, char **); int main (int argc, char **argv) { Now my doubt is extern is to tell the compiler that the particular function is not in this file but…
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
11
votes
2 answers

OCaml: Declaring a function before defining it

Is there a way to declare a function before defining it in OCaml? I'm using an OCaml interpreter. I have two functions: let myFunctionA = (* some stuff here..... *) myFunctionB (*some stuff *) let myFunctionB = (* some stuff here .... *)…
11
votes
1 answer

How to prevent error : this old-style function

I am following a tutorial and my code seems normal but I got a message which says This old-style function definition is not preceded by a prototype code.c : void viderBuffer() { int c = 0; while (c != '\n' && c != EOF) { c =…
11
votes
7 answers

Is it good programming practice in C to use first array element as array length?

Because in C the array length has to be stated when the array is defined, would it be acceptable practice to use the first element as the length, e.g. int arr[9]={9,0,1,2,3,4,5,6,7}; Then use a function such as this to process the array: int…
Ian Stewart
  • 435
  • 3
  • 11
11
votes
2 answers

What if I declare a function with empty parameter table, then pass arguments to it?

For example, #include void foo(); int main(void) { foo(); foo(42); foo("a string", 'C', 1.0); return 0; } void foo() { puts("foo() is called"); } Output: foo() is called foo() is called foo() is…
nalzok
  • 14,965
  • 21
  • 72
  • 139
11
votes
3 answers

Why is it allowed to omit the first dimension, but not the other dimensions when declaring a multi-dimensional array?

Why it is not necessary to mention first dimension of multidimensional array and necessary to mention other dimensions: int A[][][2]={{{1,2},{3,4}},{{4,5},{5,6}}}; // error int A[][2][2]={{{1,2},{3,4}},{{4,5},{5,6}}}; // OK I am not able to…
11
votes
1 answer

Linker can't find function definition in a namespace

I get this /tmp/ccnL7Yz1.o: In function 'main': main.cpp:(.text+0x70): undefined reference to 'dng::genDungeon()' main.cpp:(.text+0xf0): undefined reference to 'dng::clrDungeon(char**)' collect2: error: ld returned 1 exit status error when I'm…
11
votes
1 answer

How to define a "callable" parameter in a Python docstring?

Consider an implementation of filterNot (basically the opposite of filter): def filterNot(f, sequence): return filter(lambda x: not f(x), sequence) The parameter f can be a "function" or a "method" or a lambda -- or even an object whose class…
Chris W.
  • 1,680
  • 16
  • 35
10
votes
3 answers

an error about C struct array in formal parameter

I have got the following code: struct student_info; void paiming1(struct student_info student[]); struct student_info { int num; char name[6]; }; The IDE gives an error error: array type has incomplete element type ‘struct…
pureZer
  • 143
  • 5
10
votes
3 answers

Why parentheses are important in function pointer declaration?

I don't understand why the declaration below is accepted: typedef void (*_tStandardDeclaration)(LPVOID); while the following doesn't: typedef void *_tDeclarationWithoutParenthesis(LPVOID); typedef void* _tAlternateDeclaration(LPVOID); I am…
YeenFei
  • 3,180
  • 18
  • 26
9
votes
1 answer

Forward-declaration of a `constexpr` function inside another function -- Compiler bug?

While producing a MCVE for this problem I stumbled upon, I've found the following discrepancy between compilers: Consider the following code : // constexpr int f(); // 1 constexpr int g() { constexpr int f(); // 2 return f(); } constexpr…
Quentin
  • 62,093
  • 7
  • 131
  • 191
9
votes
3 answers

Finding out which functions are called within a given function

Possible Duplicate: Generating a Call Graph in R I'd like to systematically analyze a given function to find out which other functions are called within that very function. If possible, recursively. I came across this function in a blog post by…
Rappster
  • 12,762
  • 7
  • 71
  • 120
8
votes
5 answers

Does C support optional null parameters?

In Python, I'm used to things like def send_command(command, modifier = None): and then the modifier argument is optional, and the absence of the argument can be differentiated from an argument of 0. Is there similar functionality in C? I'm…
endolith
  • 25,479
  • 34
  • 128
  • 192
8
votes
2 answers

How do I interpret this declaration that appears to be a function declaration, but doesn't fit the usual mould?

I'm trying to decipher this declaration from sqlite3.c SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void); It seems like it is declaring a function because subsequently there is this SQLITE_PRIVATE void…
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1 2
3
36 37