Skip to main content
Prisma
Associate II
November 7, 2020
Solved

Error with pointer to a typedef struct

  • November 7, 2020
  • 2 replies
  • 1788 views

Hello, I have a problem with a typedef struct.

I made a typedef struct :

typedef struct BMP280_HandleTypeDef

{

  uint16_t dig_T1;

  int16_t dig_T2;

  int16_t dig_T3;

} BMP280_HandleTypeDef ;

In my function I declare the instance of it :

void myfunction

{

BMP280_HandleTypeDef dev;

...

MyFunction2(&dev); // I want to pass the pointer of the struct to an other function

}

// Prototype of MyFunction2

void MyFunction2 ( BMP280_HandleTypeDef *dev);

The compiler gives me this error:

error: unknown type name 'BMP280_HandleTypeDef'; did you mean 'I2C_HandleTypeDef'?

I use STM32CubeIde.

Thanks in advance for your help .

Pascal

This topic has been closed for replies.
Best answer by TDK

The definition needs to appear before its first usage, so typedef struct needs to appear before you declare MyFunction2. The order you include files is going to be important here.

2 replies

TDK
TDKBest answer
November 7, 2020

The definition needs to appear before its first usage, so typedef struct needs to appear before you declare MyFunction2. The order you include files is going to be important here.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Prisma
PrismaAuthor
Associate II
November 7, 2020

Hello TDK. Yes it works !!

I had declarated the struct in my file .h at the end ; now I have declared at first and it works correctly. Thank you very much for your help.