Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
C23 standardında yeni olan typeof
işleç, bir ifadenin türünü döndüren birli işleçtir. Tür bildirimlerinde, tür atamalarında, tür denetimlerinde vb. kullanılabilir. Bir değişkenin, işlevin veya herhangi bir C ifadesinin türünü alır.
__typeof__
anahtar sözcüğü, ile aynı işlevselliği typeof
sağlayan Microsoft'a özgü bir uzantıdır. __typeof__
anahtar sözcüğü yalnızca C'nin tüm sürümleri için derlenirken (yalnızca /std:clatest
) kullanılabilir olduğundan farklıdır typeof
ve destekleyen __typeof__
diğer derleyiciler arasında kod taşımayı kolaylaştırabilir.
typeof
söz dizimi
typeof(type)
typeof(constant-expression)
__typeof__(constant-expression)
typeof
örnek
Bu örnekte kullanılır typeof()
, ancak kullanırsanız __typeof__
davranış aynıdır.
// Compile with /std:clatest
#include <stdio.h>
double func()
{
3.14;
}
#define POINTER(T) typeof(T*)
int main()
{
auto a = func(); // the type for a (double) is inferred, but requires initialization at point of declaration
typeof(func()) b; // the type for b is double, but didn't have to be initialized at point of declaration
// Some declarations using typeof
POINTER(int) p1 = NULL; // p1 is int*
typeof(double(void))* pFunc = func; // pFunc is a pointer to a function that takes no arguments and returns a double
printf("pFunc() returns %f\n", pFunc());
return 0;
}
Gereksinimler
Visual Studio 17.9 veya üzeri ya da cl.exe
sürüm 19.39.33428 veya üzerini gerektirir.
kullanmak typeof
için ile derleyin /std:clatest
.