我在Linux中使用共享記憶體創建了一個整數向量(vectorR),代碼如下:
int shmidR, tamR;
tamR = fil*col2;
int *vectorR[tamR]; // Creating the vector
shmidR = shmget(IPC_PRIVATE, sizeof(int)*fil*col2, IPC_CREAT|0666);
vectorR[tamR] = (int*) shmat(shmidR, NULL, 0);
然后我對這個向量進行操作,最后我想列印內容看看它是否好:
for (int i = 0; i < tamR; i )
{
printf("%i", vectorR[i]);
}
但我在標題中收到警告:警告:格式“%i”需要“int”型別的引數,但引數 2 的型別為“int *”[-Wformat=]
uj5u.com熱心網友回復:
int *vectorR[tamR]創建一個 int 指標陣列。你想要的是一個整數陣列。只需使用int vectorR[tamR].
int shmidR, tamR;
tamR = fil*col2;
int vectorR[tamR]; // Creating the vector
shmidR = shmget(IPC_PRIVATE, sizeof(int)*fil*col2, IPC_CREAT|0666);
vectorR[tamR] = (int) shmat(shmidR, NULL, 0);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/525242.html
標籤:C指针警告
