Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the return type of typeof?

Tags:

c

gcc

typeof

I want to provide the type of an element as parameter to an initialization of an array of pointers to element of an unknown types

something like

void* init(type t)
  void* array = malloc(sizeof_type(t)*10));
  return array;
}

and later call for example

   init(typeof(int))

But I was not able to figure what is the return type of typeof.

I guess the sizeof_type think can be achieved using

   malloc((type) 0);

Thanks in advance

PS: this if for a vector implementatin if someone can point me to some flexiblecode i would be very thankful as well

like image 901
Ingo Avatar asked Jul 16 '10 14:07

Ingo


People also ask

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 the return type of typeof or standard JavaScript objects?

Solution(By Examveda Team) The typeof operator returns “object” for all standard JavaScript objects as functions are, and the typeof operator returns “xml”.

What type is typeof?

The Data Type of typeof It is an operator. Operators ( + - * / ) do not have any data type. But, the typeof operator always returns a string (containing the type of the operand).

What is typeof typeof in JavaScript?

Typeof in JavaScript is an operator used for type checking and returns the data type of the operand passed to it. The operand can be any variable, function, or object whose type you want to find out using the typeof operator.

What does typeof return in TypeScript?

A typeOf keyword returns the type of an identifier in TypeScript. It also acts as a Type Guard narrowing the Type in the scope where we use it.

What is typeof function?

The TypeOf function is an important tool when dealing with complex code. It allows a programmer to quickly check a variable's data type—or whether it's “undefined” or “null”—without going through the code line by line! Additionally, the TypeOf function can also check whether an operand is an object or not.


1 Answers

I don't usually use gnu (I think it is only in gnu C), but I don't think it's an expression in the normal sense that you can assign its value to a variable and later use it. I think it can only be used in very specific contexts as a type.

From the docs:

The syntax of using of this keyword looks like sizeof, but the construct acts semantically like a type name defined with typedef.

A typeof-construct can be used anywhere a typedef name could be used. For example, you can use it in a declaration, in a cast, or inside of sizeof or typeof.

like image 69
Uri Avatar answered Sep 20 '22 03:09

Uri