头文件为什么不读取C中的常量#define?

问题描述

我试图找到一种将格式传递到头文件中以在格式化数组时使用它的方法。 我的代码是这样的:

#define CONSTANT 10
#include "myHeaderFile.h"    
int main(headerFunction(array)){}

头文件:

int headerFunction(array[][CONSTANT]) { // Multidimensional array
}

这给我一个错误,提示未设置CONSTANT。 更确切地说: 错误:此处未声明“ CONSTANT”(不在函数中)

所有代码:

#include <stdio.h>
#define W 946
#define H 528
#include "myFunctions.h"


// Video resolution




// Allocate a buffer to store one frame
unsigned char frame[H][W][3] = {0};




int main(void)
{
    int x,y,count;
     
    // Open an input pipe from ffmpeg and an output pipe to a second instance of ffmpeg
    FILE *pipein = popen("ffmpeg -i 1.mp4 -f image2pipe -c:v rawvideo -pix_fmt rgb24 - ","r"); // ffmpeg -i 1.mp4 -f image2pipe -vcodec rawvideo -pix_fmt rgb24 -       
    FILE *pipeout = popen("ffmpeg -y -f rawvideo -vcodec rawvideo -pix_fmt  rgb24 -s 946x528  -i - -f mp4 -q:v 5 -an -vcodec mpeg4 output.mp4","w");
     
    // Process video frames
    while(1)
    {
        // Read a frame from the input pipe into the buffer
        count = fread(frame,1,H*W*3,pipein);
          
        // If we didn't get a frame of video,we're probably at the end
        if (count != H*W*3) break;
         
        // Process this frame
        flip(frame,x,H,W);

        // Write this frame to the output pipe
        fwrite(frame,pipeout);
    }
     
    // Flush and close input and output pipes
    fflush(pipein);
    pclose(pipein);
    fflush(pipeout);
    pclose(pipeout);
}

头文件:

int invertRGB(unsigned char frame [H][W][3],int x,int y,int H,int W){
      for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x)
      {
          frame[y][x][0] = 255 - frame[y][x][0]; 
          frame[y][x][1] = 255 - frame[y][x][1]; 
          frame[y][x][2] = 255 - frame[y][x][2];            
      }
      return frame;
}

int flip(unsigned char frame [H][W][3],int W){
      unsigned char frameTemp[H][W][3];
      for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x)
      {   
          frameTemp[(H-1)-y][(W-1)-x][0] = frame[y][x][0];
          frameTemp[(H-1)-y][(W-1)-x][1] = frame[y][x][1]; 
          frameTemp[(H-1)-y][(W-1)-x][2] = frame[y][x][2];
      }
      for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x)
      {
          frame[y][x][0] = frameTemp[y][x][0];
          frame[y][x][1] = frameTemp[y][x][1]; 
          frame[y][x][2] = frameTemp[y][x][2]; 
      }
      return frame;
}

这是我尝试创建视频编辑器的尝试:)

解决方法

这是因为在读取头文件时未定义CONSTANT

尝试一下:

#define CONSTANT 10
#include "myHeaderFile.h"
int main(headerFunction(array)){}

在“所有代码”中,您对常量(在unsigned char frame [H][W][3]中使用)和参数(在int H,int W中使用)使用了相同的名称,因此,参数也被视为宏并替换为整数,使定义无效。 在这种情况下,大小是固定的,因此您不需要参数HW,应将其删除。 不要忘记从调用点中删除多余的参数。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...