Could I retrieve the datatype from a variable in C?

后端 未结 5 1833
灰色年华
灰色年华 2020-12-11 05:42

Has a way to get the datatype in C?

For example:

int foo;

if (foo is int)
{
    // do something
}

or something like:

if (typeof(foo         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 06:44

    This is called type introspection or reflection and is not supported by the C language. You would probably have to write your own reflection library, and it would be a significant effort.

提交回复
热议问题