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
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.
Solution(By Examveda Team) The typeof operator returns “object” for all standard JavaScript objects as functions are, and the typeof operator returns “xml”.
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).
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.
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.
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.
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.
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