include file

I have a function in header file, because I want to change input matrix size when running.
When I include this header file and compile, it seems it cannot detect the change of file and macro value of X_SIZE. Could you tell me the reason, please?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//header.h
#ifdef X_SIZE
#ifdef Y_SIZE
#ifdef BYTESPERPIXEL
void readMatrix(unsigned char ImageData[X_SIZE][Y_SIZE][BYTESPERPIXEL], char *filename){};

//main.cpp
#define X_SIZE 1080
#define Y_SIZE 1920
#define BYTESPERPIXEL 3
#include "header.h"

unsigned char imageData[X_SIZE][Y_SIZE][BYTESPERPIXEL];
s = "images/image_input_2.raw";
readMatrix(imageData, s);
matrix2Pointer(imageData, &rdata, &gdata, &bdata);
Macros expand before compile time and can't be changed at compile time.
Last edited on
Why don't you pass the sizes as parameters?

And if you are using C++ (probably, not, because you are using a raw char pointer instead of string), you could (and should) replace #define 's like these by const variables.
I need pass a pointer of matrix instead of a regular pointer.

I am using C++.
You could pass a simple unsigned char pointer and the sizes (x, y and pixel):

void readMatrix(unsigned char * ImageData, unsigned int xSize, unsigned int ySize, unsigned int bytesPerPixel, const string & filename);
Or even better, create a class.
Topic archived. No new replies allowed.