Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check a certain type is already defined in C compiler?

If a compiler has a certain type (ex. ptrdiff_t) as an embedded type, I don't want to typedef it again. I know that below code does not work properly that I expected.

#ifndef ptrdiff_t 
    typedef long int ptrdiff_t;
#endif

How can I check a certain type is already defined in the C compiler?

like image 731
lqez Avatar asked Sep 24 '12 03:09

lqez


1 Answers

There's no way to do that in general. In some cases there may be a macro that is defined at the same time as the type that you can use.

In your particular example, you can #include <stddef.h>, which should always define ptrdiff_t.

like image 164
Vaughn Cato Avatar answered Sep 28 '22 09:09

Vaughn Cato