Home > Software design >  converting a string to c reserved words
converting a string to c reserved words

Time:07-14

I'm trying to print out the size of various data types I have in an array as strings, like so:

printf("%lu", sizeof(list_of_datatypes[i]))

A string for example would be "char", or "unsigned int". Is there a way I could get sizeof to see them as the reserved words they are in c?

CodePudding user response:

You can't do that. The sizeof operator takes expressions or type names as an argument, and the result is evaluated at compile time (except for variably-modified types). It does not treat a string such as ”char” as a type name.

Is there any way to explicitly convert it?

No.

  • Related