AnsweredAssumed Answered

Declare Typedef array size with external Macro

Question asked by Hein Wessels on May 29, 2018

Good day everyone,

I'm trying to create a typedef for array in a header file. The size of this array should be defined by a macro from another header file. A quick snippet of my code is as follows:

 

HTPA.h

#ifndef HTPA_H_

#define HTPA_H_

#define HTPA_IMG_WIDTH 80 // The array size I want

#endif /* HTPA_H_ */

 

ads.h

#ifndef ADS_H_
#define ADS_H_

#include "HTPA.h"

typedef uint16_t ADS_GradImg [HTPA_IMG_WIDTH ]; // The array typedef I want

#endif /* ADS_H_ */

 

When I try to compile this I get the error:

../Inc/ads.h:65:31: error: 'HTPA_IMG_WIDTH ' undeclared here (not in a function)

I have searched the web, but can't find a similar problem. I have a hunch that it is because how the pre-processor/compiler works, but can't seem to find a solution around it.

Can I make this work? Or will I have to use a workaround?

Thanks in advance!

Outcomes