A function pointer is a type of pointer in C, C++, D, and other C-like programming languages. When dereferenced, a function pointer invokes a function, passing it zero or more arguments just like a normal function. In programming languages like C, function pointers can be used to simplify code, such as replacing large switch statements.

PropertyValue
p:abstract
  • A function pointer is a type of pointer in C, C++, D, and other C-like programming languages. When dereferenced, a function pointer invokes a function, passing it zero or more arguments just like a normal function. In programming languages like C, function pointers can be used to simplify code, such as replacing large switch statements. Function objects, or functors, are similar to function pointers, and can be used in similar ways. A functor is an object of a class type that implements the function-call operator, allowing the object to be used within expressions using the same syntax as a function call. Functors are more powerful than simple function pointers, being able to contain their own data values, and allowing the programmer to emulate closures, among other uses. Many "pure" object-oriented languages (such as Java) do not support function pointers. Something similar can be implemented in these kinds of languages, though, using references to interfaces that define a single member function. Microsoft .NET languages such as C# and Visual Basic .NET implement type-safe function pointers with delegates. In other languages that support first-class functions, functions are regarded as data, and can be passed, returned, and created dynamically directly by other functions, eliminating the need for function pointers. Extensively using function pointers to call functions may produce a slow-down for the code on modern processors, because branch prediction may not be able to figure out where to branch to (it depends on the value of the function pointer at run time). (en)
  • 関数へのポインタは、C, C++, Dやその他Cを基にしたプログラミング言語におけるポインタの一種である。関数へのポインタを参照外し(デレファレンス)して実引数を与えると、そのポインタが指し示す関数を呼び出せる。Cなどのプログラミング言語では、switch文を置き換えてコードを単純にするために使われることがある。 関数オブジェクト(もしくはファンクタとも呼ぶ)も関数へのポインタと同じような使い方が可能だが、関数オブジェクトは関数呼出演算子を実装したクラスなどのオブジェクトであるという点が異なっている。そのため、関数オブジェクトはデータを保持でき、クロージャを再現することもできる。ゆえに、関数オブジェクトは、単純な関数へのポインタよりも強力である。 多くの「純粋な」オブジェクト指向プログラミング言語(Javaなど)では、関数へのポインタを使用できないが、そのような言語では、メソッドを1つだけ持つインタフェースを使用することで同様のことを行える。また、C#やVisual Basic .NETなどといった.NET Framework用の言語では、関数へのポインタを型安全にしたものとして、デリゲートが使用可能である。 第一級関数を使用できる言語では、関数も引数で渡したり、戻り値で返したり、他の関数から動的に作成したりできるなどデータ同様に扱えるため、関数へのポインタは必要とされない。 (ja)
p:hasPhotoCollection
p:reference
p:wikipage-ja
rdfs:comment
  • A function pointer is a type of pointer in C, C++, D, and other C-like programming languages. When dereferenced, a function pointer invokes a function, passing it zero or more arguments just like a normal function. In programming languages like C, function pointers can be used to simplify code, such as replacing large switch statements. (en)
  • 関数へのポインタは、C, C++, Dやその他Cを基にしたプログラミング言語におけるポインタの一種である。関数へのポインタを参照外し(デレファレンス)して実引数を与えると、そのポインタが指し示す関数を呼び出せる。Cなどのプログラミング言語では、switch文を置き換えてコードを単純にするために使われることがある。 (ja)
rdfs:label
  • Function pointer (en)
  • 関数へのポインタ (ja)
skos:subject
foaf:page
p:redirect