function-declaration Questions

2

Solved

Is the following a standard C function declaration according to ISO/IEC 9899:2017 (c17)? int foo(int (bar), int (baz)); If so, please point me to the section in the standard that defines this. In ...
Acephalous asked 14/3 at 21:16

2

Solved

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...

5

Solved

Consider these two function definitions: void foo() { } void foo(void) { } Is there any difference between these two? If not, why is the void argument there? Aesthetic reasons?
Forgiving asked 9/9, 2008 at 0:48

1

Solved

Consider: #include <iostream> using namespace std; void Change(int arr[3]) { for (int i = 0; i < 3; i++) { arr[i] = 1; } } int Test() { int arr[3] = { 0, 0, 0 }; for (int i =...

4

Solved

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 newval, gint *preval) { retu...
Confiscate asked 16/7, 2023 at 12:22

2

Solved

For the code: int hi(int); int hi(); int main() { hi(3); } I don't get any compilation errors (calling hi(); without arguments does get a compilation error). I expected that the compiler would co...
Whichsoever asked 3/5, 2023 at 6:38

6

Solved

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, ...

7

Solved

I am trying to create a generic function that can take an optional argument. Here's what I have so far: func somethingGeneric<T>(input: T?) { if (input != nil) { print(input!); } } somet...
Subgroup asked 16/3, 2016 at 15:1

4

Solved

I'm more like C++ than C, but this simple example of code is big surprise for me: int foo() { return 3; } int main() { int x; foo(&x); return x; } https://godbolt.org/z/4ov9nTzjM No warni...

2

Solved

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 a...

7

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 fu...
Kinney asked 28/1, 2021 at 12:44

2

Solved

One thing I do not fully understand about Haskell is declaring functions and their types: is it something you have to do or is it just something you should do for clarity? Or are there certain scen...
Rickirickie asked 5/2, 2021 at 16:56

5

Solved

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 f...
Consultation asked 22/10, 2020 at 8:2

3

Solved

If I declare two functions a and b: def a(x): return x**2 b = lambda x: x**2 I can not use type to differentiate them, since they're both of the same type. assert type(a) == type(b) Also, t...
Whist asked 8/1, 2019 at 14:48

4

Solved

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 ...
Rattlepate asked 28/7, 2020 at 19:16

5

Solved

I have noticed that both work, what is the correct way to use inline here? static inline int getAreaIndex() OR inline static int getAreaIndex() Plus, getAreaIndex contains a large loop. somet...
Fyn asked 10/5, 2020 at 15:3

4

Solved

I know that here are some explanations about the difference between p++, ++p and p+1 but I couldn't understand it clearly yet, especially when it's not working with that function: void replace(cha...

31

Solved

For example, imagine a simple mutator that takes a single boolean parameter: void SetValue(const bool b) { my_val_ = b; } Does that const actually have any impact? Personally I opt to use it exten...

3

Solved

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 typ...
Hahnert asked 22/6, 2010 at 12:38

4

Solved

I would like to know if it is possible to define a function type using typedef, I tried this syntax: typedef int (*) (void *, void *) order; But it doesn't work. Error message : expected identi...

3

Solved

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 ...
Connection asked 22/7, 2019 at 10:4

3

Solved

I am learning the basics of C++ and OOP in my university now. I am not 100% sure how a function pointer works when assigning functions to them. I encountered the following code: void mystery7(int...

7

Solved

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 <iostream> i...

2

Solved

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 declara...
Tishtisha asked 6/2, 2019 at 5:58

9

Solved

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 t...
Churrigueresque asked 25/8, 2010 at 20:26

© 2022 - 2024 — McMap. All rights reserved.