나는 Keil 프로젝트에서 c를 사용하여 작업 중이다. 내 파일 중 하나에서 맨 위에있는 일부 변수를 정적으로 정의했습니다. 이 파일의 일부 기능에서 사용하고 switch/case 문에서도 사용합니다.switch 문에서 정적 변수
static uint8_t* imageData = 0;
static uint32_t height = 0;
static uint32_t width = 0;
static uint32_t stride = 0;
코드의 중간에 :
switch (pMsg->MsgId)
{
case WM_CREATE:
{
CAMERA_Init();
AMProcessor *processor = new AMProcessor();
struct block blocks[2] = {
{2, 240, 160},
{2, 160, 120}
};
processor->initBlocks(blocks, 2);
stride = 480; //sample_image.width;
processor->Initialize(480, 272, 480, InputTypes::CHROMA_MOBILE, InputTypes::RGB);
BSP_LED_Toggle(LED3);
while(1){
const PictureOutput* picOut = processor->ProcessImage((uint8_t *)CAMERA_FRAME_BUFFER);
break;
}
}
및 하단 나는 또한이를 사용하는 함수의 몇이 변수가 정의되어 있습니다 상단에
: 예를 들어, 변수. 그러나 맨 위에 정의 된 4 개의 변수가 초기화되었지만 참조 된 적이 없다는 경고가 나타납니다. 그들이 정적이 아니라면 나는이 경고를 얻지 못한다. 그러나 나는 (나는 제거하려고 노력하고있는) 하드 오류 오류를 얻는다.
내 질문은 왜 이들이 참조되지 않는 것입니까? 정적 정의와는 분명히 관련이 있습니다. 그러나 정적 정의는 어떻게 참조 될 수 있습니까?
설명 : 나는이 메시지를 모두 보았습니다. 경고 : # 177-D : 변수 "imageData의"는 선언하지만이처럼 보이는이 모든 변수를 사용하여 하단의 기능이
를 참조 적이 :bool ReadImageFromPgmFile(const char* pFileName, uint32_t &height, uint32_t &width, uint8_t*& ImgData) {
if (pFileName == 0) {
return false;
};
// read data from file
if (strstr(pFileName, ".pgm") || strstr(pFileName, ".PGM")) {
FILE *pPgmFile = fopen(pFileName, "r");
if (pPgmFile == NULL) {
fprintf(stderr, "Cannot open PGM file '%s'.\n", pFileName);
return false;
};
char x = fgetc(pPgmFile);
char y = fgetc(pPgmFile);
if (x != 'P' || y != '5') {
fprintf(stderr, "Invalid PGM file '%s'.\n", pFileName);
return false;
};
uint32_t maxvalue;
fscanf(pPgmFile, "%d", &width);
fscanf(pPgmFile, "%d", &height);
fscanf(pPgmFile, "%d", &maxvalue);
if (maxvalue > 255) {
fprintf(stderr, "File '%s' has incorrect format.\nOnly 8-bit PGMs are supported by this reader.\n", pFileName);
return false;
};
ImgData = new uint8_t[width*height];
memset(ImgData, 0, width*height);
fgetc(pPgmFile); // skip new line character
uint32_t nPixelsRead = fread(ImgData, 1, width * height, pPgmFile);
fclose(pPgmFile);
if (nPixelsRead != width * height) {
fprintf(stderr, "PGM file '%s' does not contain all pixels.\n", pFileName);
return false;
};
return true;
}
return false;
};
나는 그 변수를 어디에서 사용하고 있는지 보지 않고있다 ... – Joe
나는 단지'stride' 만 사용되는 것을 볼 수있다. 정확히 무엇이 오류 메시지입니까? – Steve