Could I retrieve the datatype from a variable in C?

后端 未结 5 1839
灰色年华
灰色年华 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:41

    The only time you wouldn't know the type is if the type of foo is defined by a typedef -- if that's the case, your example should reflect it. And why do you need to something dependent on the type? There may well be a way to solve your actual problem, but you haven't presented your actual problem.

提交回复
热议问题