Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ typeof operator

Tags:

c++

typeof

very short question.

Is C++ typeof operator standard? de facto standard? which compilers do not provided it (besides Microsoft C++)?

like image 499
Anycorn Avatar asked Apr 16 '10 03:04

Anycorn


People also ask

What is typeof operator in C?

The typeof keyword is a new extension to the C language. The Oracle Developer Studio C compiler accepts constructs with typeof wherever a typedef name is accepted, including the following syntactic categories: Declarations. Parameter type lists and return types in a function declarator.

What does typeof () return in C?

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.

What is __ typeof __ in C?

The __typeof__ operator returns the type of its argument, which can be an expression or a type. The language feature provides a way to derive the type from an expression. Given an expression e , __typeof__(e) can be used anywhere a type name is needed, for example in a declaration or in a cast.

What is typeof used for?

typeof is a JavaScript keyword that will return the type of a variable when you call it. You can use this to validate function parameters or check if variables are defined. There are other uses as well. The typeof operator is useful because it is an easy way to check the type of a variable in your code.


2 Answers

The typeof operator is nonstandard, but the upcoming C++ standard will have decltype.

like image 88
dan04 Avatar answered Sep 20 '22 12:09

dan04


As noted, C++0x has decltype. You can take a look at Boost.Typeof in the meantime.

like image 45
Ismail Badawi Avatar answered Sep 18 '22 12:09

Ismail Badawi