Error: '...' does not name a type

Hi all,

This is my first forum post ever, so please let me know if I have not followed standard post procedures. I am trying to define a struct in a separate header file, "test_header.h" and then create an instance of this in my main file, "test.ino". The code does nothing, but highlights my problem.

For some reason, I get the compilation error: "arm0 does not name a type". I am confused since arm0 clearly has been declared right before as a "struct store_arm_data_struct".

Thank you for your help!

test_header.h (183 Bytes)

test.ino (194 Bytes)

This is my first forum post ever, so please let me know if I have not followed standard post procedures.

Welcome to the forum

Please post your code here rather than attaching it as it is so small. When you post it please use code tags. Don't know what they are ? then read this before posting a programming question

If you make it easier to copy your code to an editor for examination you are likely to get a faster and more complete reply

https://en.cppreference.com/w/c/language/struct_initialization

Hi UKHeliBob,

Thanks for letting me know. For everyone's convenience, here is my test code so you don't have to download those files:

test.ino:

#include "test_header.h"

struct store_arm_data_struct arm0;
arm0.motor0_step_pin = 2;
arm0.motor1_step_pin = 3;
arm0.motor0_dir_pin = 4;
arm0.motor1_dir_pin = 5;

test_header.h:

#ifndef _ARM_DATA_H_
#define _ARM_DATA_H_

struct store_arm_data_struct {
    int motor0_step_pin;
    int motor1_step_pin;
    int motor0_dir_pin;
    int motor1_dir_pin;
};

#endif

Hi bperrybap,
Thank you for sending this reference. I am sure that I have followed the correct struct initialization procedure for c++. God I just realized that since this is Arduino, you need to modify variables inside the void loop() or void setup() functions instead of outside... Thanks for the help everyone.

alvin_shek_99:
I am sure that I have followed the correct struct initialization procedure for c++.

#include "test_header.h"

struct store_arm_data_struct arm0 = {
 .motor0_step_pin = 2, 
 .motor1_step_pin = 3,
 .motor0_dir_pin = 4,
 .motor1_dir_pin = 5
};

void setup(){}

void loop(){}