Questions tagged [function-definition]

395 questions
643
votes
8 answers

What does -> mean in Python function definitions?

I've recently noticed something interesting when looking at Python 3.3 grammar specification: funcdef: 'def' NAME parameters ['->' test] ':' suite The optional 'arrow' block was absent in Python 2 and I couldn't find any information regarding its…
Krotton
  • 6,641
  • 3
  • 13
  • 12
77
votes
5 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…
19
votes
3 answers

is there any way for multiple where statement in Haskell

i tried to write 3-4 where statement in a one function but i get error and couldnt do it , i tried to do something like that : foo x= | x == foo1 = 5 | x == foo2 =3 | x == foo3 =1 | otherwise =2 where foo1= samplefunct1 x foo2= samplefunct2…
11
votes
1 answer

Should I define my Cython function using def, cdef, or cpdef for optimal performance?

How can I know whether to use def, cdef or cpdef when defining a Cython function, assuming I want optimal performance?
PDiracDelta
  • 1,728
  • 3
  • 15
  • 33
6
votes
3 answers

How to pass pointer to function and dynamically allocate memory within function C++

I'm trying to declare a pointer and pass that pointer to a function where memory is allocated. Here is a minimal example: #include #include using namespace std; void alloc_mem(int &size, double *x); int main() { …
5
votes
4 answers

Function with 0 arguments - void vs void*?

I know that you can declare a function without any arguments simply like this: void test() { cout << "Hello world!!" << endl; } But I have also seen void test(void) { cout << "Hello world!!" << endl; } and void test(void*) { cout <<…
user2039981
5
votes
3 answers

Python3 function definition, arrow and colon

I have found the following python function definition: def reverseString(self, s: 'List[str]') -> 'None': I don't quite understand 'List[str]' and -> 'None'. I have found that the arrow is a function annotation but I couldn't find anything useful…
Amir
  • 137
  • 3
  • 13
5
votes
2 answers

Function definitions of built-in functions in C

We include header files like stdio.h in our C programs to use the built-in library functions. I once used to think that these header files contained the function definitions of the built-in functions that we may use in our programs. But soon found…
J...S
  • 4,713
  • 1
  • 15
  • 34
5
votes
1 answer

Error lnk2005 already defined in .obj

There are many question about this error. But they are related to only a single variable. test.h namespace World { enum Objects { TERRAIN = 1, BOX = 2, SPHERE = 4, CAPSULE = 8 }; void…
zakjma
  • 1,740
  • 11
  • 34
  • 65
4
votes
3 answers

Why should we use double pointer for adding node in front/back, but not in the middle?

I have this code which creates new node at the very front: void push(struct Node** head_ref, int new_data) { struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next =…
4
votes
3 answers

using binary search to find the first capital letter in a sorted string

I wrote the following code to find the first capital letter in a string using binary search: char first_capital(const char str[], int n) { int begin = 0; int end = n - 1; int mid; while (begin <= end) { mid = (begin +…
Jason
  • 85
  • 5
4
votes
3 answers

Binary search tree lookup output

I am attempting to implement a lookup function for a binary search tree. While it does return true if I lookup the root of the tree, when I lookup other entries that are in the tree it returns false. When I debugged it the function seemed to return…
4
votes
2 answers

Is it possible to define a function dynamically in ZSH?

I would like to define a series of functions dynamically in ZSH. For example: #!/bin/zsh for action in status start stop restart; do $action() { systemctl $action $* } done However, this results in four identical functions which…
4
votes
1 answer

R: Where are formals for a function stored in memory?

When a function has been defined but has not yet been called, do the formals that do not have default values exist? If they do, do they exist in the execution environment, or in the environment where the function definition is located, or somewhere…
andrewH
  • 1,979
  • 1
  • 13
  • 26
4
votes
1 answer

How to hash a class or function definition?

Background When experimenting with machine learning, I often reuse models trained previously, by means of pickling/unpickling. However, when working on the feature-extraction part, it's a challenge not to confuse different models. Therefore, I want…
lenz
  • 4,586
  • 4
  • 22
  • 35
1
2 3
26 27