Structure Arduino

Hello, I am trying to understand someone else code and i am a bit lost.

typedef union accel_t_gyro_union
{
  struct
  {
    uint8_t x_accel_h; //unsigned integer of length 8 bits
    uint8_t x_accel_l;
  } reg;
  struct 
  {
    int16_t x_accel; //int16_t is a 16bit integer. uint16_t is an unsigned 16bit integer.
  } value;
};

Q1> what is typedef union ?

uint8_t *buffer

Q2> what does * do ?

a union maps multiple datatypes on the same memory location. in your example it maps 2 structs of different size on the same memory. - http://www.cplusplus.com/doc/tutorial/other_data_types/ -

unions are not often used, but they have nice properties see the example below

typedef union bl
{
  long x;
  byte ar[4];
};

Can you see what it does?

The * is a dereference operator It means buffer is a pointer to a memory location holding an uint8_t see - http://www.cplusplus.com/doc/tutorial/pointers/ - for the details

a typedef allows you to string some types together and call it a new name to make other code clearer. IOW, somewhere in your headers there is a

typedef  unsigned long size_t

typedef allows you to create an alternative name for something, although in your first example there, it doesn't actually define a name for it.

Thanks for the replies, I will read more about it thanks again.

Here is another code,

  Serial.println("Let the program begin");
  Serial.println(F("Let the program begin"));

It gives the same thing, anyone know what is the different between them ?

Thanks

The difference is the first one wastes precious RAM.

And the second stores the char array in PROGMEM (flash) which is less precious (32K flash vs 2K RAM)

variables stored in PROGMEM cannot be changed during the program and need a tiny bit more processing to be used. Typically not noticeable.

Thanks again

error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) &accel_t_gyro, sizeof(accel_t_gyro));

I kinda understand most of the line above but (uint8_t *) &accel_t_gyro

I know &accel_t_gyro look at the address instead of the value but what does (uint8_t *) with a bracket do and the *?

sorry for my silly question