cancel
Showing results for 
Search instead for 
Did you mean: 

Declare Typedef array size with external Macro

Hein Wessels
Associate
Posted on May 29, 2018 at 15:25

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!

#gcc #c #typedef #header #macro
2 REPLIES 2
Jan Waclawek
Senior II
Posted on May 29, 2018 at 17:38

So is it HTPA_IMG_WIDTH or HTPA_IMG_HEIGHT?

JW

Posted on May 30, 2018 at 11:39

Both. Sorry, I seemed to have written the question wrong. I have both defined.