Questions tagged [function-signature]

80 questions
85
votes
4 answers

Is char *envp[] as a third argument to main() portable

In order to get an environment variable in a C program, one could use the following: getenv() extern char **environ; But other than the above mentioned, is using char *envp[] as a third argument to main() to get the environment variables…
42
votes
7 answers

Is there a tool that generates P/Invoke signatures for arbitrary unmanaged DLL?

I stumbled upon a tool that generates P/Invoke signatures for Microsoft's own unmanaged DLLs: PInvoke Interop Assistant Is there a similar tool that will generate P/Invoke signatures for third-party unmanaged DLLs? Alternately, any way to feed a…
GregC
  • 7,737
  • 2
  • 53
  • 67
37
votes
5 answers

Required parameter $xxx follows optional parameter $yyy

Deprecated: Required parameter $xxx follows optional parameter $yyy in... Since upgrading to PHP 8.0 this error is thrown when running code like this: function test_function(int $var1 = 2, int $var2) { return $var1 / $var2; } This has worked…
miken32
  • 42,008
  • 16
  • 111
  • 154
35
votes
4 answers

How to compare the signature of two functions?

Is there a way to check if two functions have the same signature? For example: int funA (int a, int b); int funB (int a, int b); float funC (int a, int b); int funD (float a, int b); In this example, funA and funB is the only combination of…
35
votes
2 answers

Function pointers with default parameters in C++

How does C++ handle function pointers in relation to functions with defaulted parameters? If I have: void foo(int i, float f = 0.0f); void bar(int i, float f); void (*func_ptr1)(int); void (*func_ptr2)(int, float); void (*func_ptr3)(int, float =…
19
votes
4 answers

What's the meaning of multiple const qualifiers?

Code: const char* const* const* foo(int bar); I've seen double consts before which prevent the modification of the pointer too. First time i've seen triple const in my life. Wondering what its use is.
Learath2
  • 20,023
  • 2
  • 20
  • 30
18
votes
1 answer

How to define template function within template class in *.inl file

I write template declaration in *.hpp file and their "definition" in *.inl file linked from *.hpp just like this: //*.hpp template class SomeClass { public: void someMethod(); }; //*.inl template
relaxxx
  • 7,566
  • 8
  • 37
  • 64
15
votes
4 answers

Can an unnamed parameter of function have a default value?

Is the following code legal in C++? void f(void* = 0) {} int main() { f(); } Which page of the C++ standard states that this usage is legal?
xmllmx
  • 39,765
  • 26
  • 162
  • 323
13
votes
2 answers

Why is return type before the function name?

The new C++11 standard adds a new function declaration syntax with a trailing return type: // Usual declaration int foo(); // New declaration auto foo() -> int; This syntax has the advantage of letting the return type be deduced, as…
authchir
  • 1,605
  • 14
  • 26
11
votes
4 answers

Ternary operator and function signature

Let's say I have a C++ class with two functions like class MyClass { bool Foo(int val); bool Foo(string val); } Is it possible to use the ternary operator like this MyClassInstance->Foo(booleanValue?24:"a string"); and have a different…
Yannick Blondeau
  • 9,465
  • 8
  • 52
  • 74
10
votes
2 answers

Any way to find all possible kwargs for a function in python from cli?

Is there a way to discover the potential keyword arguments for a function in python from the command line? without looking at the source or docs. Sometimes the source is to c lib even that isn't visible
Riz
  • 1,055
  • 11
  • 18
9
votes
4 answers

How to declare two functions taking each other's signature as argument?

Is it possible to emulate something like this: typedef boost::function B; typedef boost::function A; The main goal is to be able to write code like this (in pseudo-c++): void a_(B b) { // ... b(a_); } void b_(A a) { // ... …
abyss.7
  • 13,882
  • 11
  • 56
  • 100
9
votes
2 answers

TypeScript - check if object's property is a function with given signature

I have a function that gets a property from an object. // Utils.ts export function getProperty(obj: T, key: string): T[K] { if (key in obj) { return obj[key as K]; } throw new Error(`Invalid object member…
Forseti
  • 2,587
  • 6
  • 21
  • 32
9
votes
3 answers

Whats the pythonic way to handle empty *args when creating a set?

Defining a function, MyFunction(argument, *args): [do something to argument[arg] for arg in *args] if *args is empty, the function doesn't do anything, but I want to make the default behavior 'use the entire set if length of *args == 0' def…
justin cress
  • 1,745
  • 5
  • 24
  • 35
7
votes
0 answers

Remove function argument after setting it to a value with functools.partial

I would like to use functools.partial to set a certain argument to a constant and at the same time remove the argument altogether. Let me explain it using a simple example. from functools import partial def f(a, b): return a * b g = partial(f,…
johnbaltis
  • 1,413
  • 4
  • 14
  • 26
1
2 3 4 5 6