e.g #pragma data_seg("share_data") int a = 0; int b; #pragma data_seg() __declspec(allocate("share_data")) int c = 1; __declspec(allocate("share_data")) int d; 3. deprecated 用__declspec(deprecated ) 说明一个函数,类型,或别的标识符在新的版本或未来版本中不再支持,你不应该用这个函数或类型。它和#pragma deprecated作用一样。
e.g #define MY_TEXT "function is deprecated" void func1(void) {} __declspec(deprecated) void func1(int) { printf("func1n");} __declspec(deprecated("** this is a deprecated function **")) void func2(int) { printf("func2n");} __declspec(deprecated(MY_TEXT)) void func3(int) { printf("func3");} int main() { fun1(); fun2(); fun3(); } 4.dllimport 和dllexport
e.g #include #include #define M 800#define N 600#define P 700float * mempool, * memptr; __declspec(restrict) float * ma(int size) { float * retval; retval = memptr; memptr += size; return retval; } __declspec(restrict) float * init(int m, int n) { float * a; int i, j; int k=1; a = ma(m * n); if (!a) exit(1); for (i=0; i for (j=0; j a[i*n+j] = 0.1/k++; return a; } __declspec(noalias) void multiply(float * a, float * b, float * c) { int i, j, k; for (j=0; j
for (i=0; i for (k=0; k c[i * P + j] = a[i * N + k] * b[k * P + j]; }
int main() { float * a, * b, * c; mempool = (float *) malloc(sizeof(float) * (M*N + N*P + M*P)); if (!mempool) puts("ERROR: Malloc returned null"); exit(1); memptr = mempool; a = init(M, N); b = init(N, P); c = init(M, P); multiply(a, b, c); } 8. noinline__declspec(noinline)