Questions tagged [function-prototypes]

Anything related to C and C++ function prototypes. Function prototypes are a way to describe the interface of a function to the client code.

Anything related to C and C++ function prototypes. Function prototypes are a way to describe the interface of a function to the client code, in fact function prototypes convey the following information about a function:

  • its name;
  • its return type;
  • the list of its parameters, each listed with its type and name (this latter is optional).

For example, in this function definition:

int DoSomething(double a, char b, int* c)
{
    // function body
}

the prototype is:

int DoSomething(double a, char b, int* c);

or just only:

int DoSomething(double, char, int*);
288 questions
394
votes
11 answers

Why does a function with no parameters (compared to the actual function definition) compile?

I've just come across someone's C code that I'm confused as to why it is compiling. There are two points I don't understand. The function prototype has no parameters compared to the actual function definition. The parameter in the function…
AdmiralJonB
  • 1,896
  • 2
  • 18
  • 25
107
votes
11 answers

How to set the prototype of a JavaScript object that has already been instantiated?

Suppose I have an object foo in my JavaScript code. foo is a complex object and it is generated somewhere else. How can I change the prototype of the foo object? My motivation is setting appropriate prototypes to objects serialized from .NET to…
Vivian River
  • 28,530
  • 54
  • 179
  • 298
97
votes
5 answers

c++0x: proper way to receive a lambda as parameter by reference

What is the right way to define a function that receives a int->int lambda parameter by reference? void f(std::function< int(int) >& lambda); or void f(auto& lambda); I'm not sure the last form is even legal syntax. Are there other ways to define…
lurscher
  • 23,085
  • 26
  • 113
  • 178
97
votes
6 answers

Javascript when to use prototypes

I'd like to understand when it is appropriate to use prototype methods in js. Should they always be used? Or are there cases where using them is not preferred and/or incurs a performance penalty? In searching around this site on common methods…
opl
  • 1,077
  • 1
  • 9
  • 8
70
votes
5 answers

What are the valid signatures for C's main() function?

What really are the valid signatures for main function in C? I know: int main(int argc, char *argv[]) Are there other valid ones?
Prady
  • 9,658
  • 38
  • 120
  • 170
59
votes
10 answers

Must declare function prototype in C?

I am kind of new to C (I have prior Java, C#, and some C++ experience). In C, is it necessary to declare a function prototype or can the code compile without it? Is it good programming practice to do so? Or does it just depend on the compiler? (I am…
Mohit Deshpande
  • 48,747
  • 74
  • 187
  • 247
52
votes
10 answers

Javascript prototype operator performance: saves memory, but is it faster?

I read here (Douglas Crockford) using prototype operator to add methods to Javascript classes saves also memory. Then I read in this John Resig's article "Instantiating a function with a bunch of prototype properties is very, very, fast", but is he…
Marco Demaio
  • 30,990
  • 33
  • 122
  • 155
36
votes
10 answers

Mongoose/MongoDB result fields appear undefined in Javascript

Is there something that I'm missing that would allow item to log as an object with a parameter, but when I try to access that parameter, it's undefined? What I've tried so far: console.log(item) => { title: "foo", content: "bar" } , that's…
30
votes
1 answer

What are those strange array sizes [*] and [static] in C99?

Apparently the following function prototypes are valid in C99 and C11: void foo(int a[const *]); void bar(int a[static volatile 10]); What is the purpose of those strange subscript notations *, static, and CV qualifiers? Do they help distinguish…
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
26
votes
3 answers

Put name of parameters in C function prototypes?

When declaring functions in C, you should set a prototype in which you do not need to write the name of parameters. Just with its type is enough. void foo(int, char); My question is, is it a good practice to also include names of parameters?
eversor
  • 2,787
  • 2
  • 23
  • 41
25
votes
10 answers

Extracting C / C++ function prototypes

I want to do this: extract_prototypes file1.c file2.cpp file3.c and have whatever script/program print a nice list of function prototypes for all functions defined in the given C / C++ files. It must handle multi-line declarations nicely. Is there…
Peter
  • 114,224
  • 47
  • 167
  • 205
21
votes
5 answers

Write the prototype for a function that takes an array of exactly 16 integers

One of the interview questions asked me to "write the prototype for a C function that takes an array of exactly 16 integers" and I was wondering what it could be? Maybe a function declaration like this: void foo(int a[], int len); Or something…
sriks
  • 543
  • 2
  • 6
  • 17
20
votes
4 answers

C++ : Meaning of const char*const*

In one of the C++ programs, I saw a function prototype : int Classifier::command(int argc, const char*const* argv) What does const char*const* argv mean? Is it the same as const char* argv[]? Does const char** argv also mean the same?
vigs1990
  • 1,379
  • 4
  • 12
  • 18
18
votes
3 answers

Javascript namespace declaration with function-prototype

I know, this is often discussed. But after searching around like someone out of the 19th century, I need some advice. I have no problem by declaring a "namespace", but when it comes to a prototype.foo function, I stuck. I found a way, but I don't…
Johnny Sterlak
  • 401
  • 1
  • 4
  • 12
17
votes
5 answers

Do comments affect performance?

Am I correct to say that JavaScript code isn't compiled, not even JIT? If so, does that mean that comments have an affect on performance, and I should be very careful where I put place my comments? Such as placing function comments above and outside…
Nick Rolando
  • 25,176
  • 13
  • 72
  • 111
1
2 3
19 20