Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get type name as string in C, GCC

Tags:

c

gcc

Is there some 'builtin' extension in GCC to get type name of expression in C? (As a string, i.e. 'const char*').

like image 343
dilettant Avatar asked May 24 '11 13:05

dilettant


1 Answers

First. You want to obtain type of a C expression at runtime. The problem is that types are erased during compilation and the machine code is almost typeless, it does not contains anything else than 8/16/32/64 bit integers and 32/64/80 bit floating point numbers (in case of x86). Types are compile time entity for C (C++ may retain some information about types in runtime though, because of its object-oriented nature, it associates types with classes, but it's hard to track PODs and primitive types).

Second. You want a type of a C expression. Sometimes it's hard to say what a given C expression be at runtime.

Thus there's no way to obtain C expression type at runtime.

like image 103
Dmytro Sirenko Avatar answered Oct 01 '22 13:10

Dmytro Sirenko