We can get the type returned by function in gcc using the typeof operator as follows:
typeof(container.begin()) i;
Is it possible to do something similar for functions taking some arguments, but not giving them? E.g. when we have function:
MyType foo(int, char, bool, int);
I want to retrieve this "MyType" (probably using typeof operator) assuming I know only the name of function ("foo") and have no knowledge about arguments it takes. Is it possible?
In other languages, such as C# or D and, to some degree, in C (as part of nonstandard extensions and proposed standard revisions), the typeof operator returns the static type of the operand. That is, it evaluates to the declared type at that instant in the program, irrespective of its original form.
__typeof__() and __typeof() are compiler-specific extensions to the C language, because standard C does not include such an operator. Standard C requires compilers to prefix language extensions with a double-underscore (which is also why you should never do so for your own functions, variables, etc.)
The typeof operator returns a string indicating the type of the unevaluated operand.
typeof
is a non-standard extension, so don't use it if you want your code to be portable.
Its syntax is typeof(expression)
, so you need to give it an expression calling the function (whose type is therefore MyType
), like this:
typeof(foo(int(),char(),bool(),int()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With