Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

undeclared identifier error with a structure in C

I have a structure ST_transaction_t that contains 2 structures, an enumeration and uint32_t members, when I declare the structure ST_transaction account1 I get account1': undeclared identifier error. When I remove the enumeration typed member from the structure it works.

Here is the part of the code with the problem:

typedef struct ST_transaction_t
{
    ST_cardData_t cardHolderData;
    ST_terminalData_t terminalData;
    EN_transState_t transState;
    uint32_t transactionSequenceNumber;
}ST_transaction_t;
typedef enum EN_transState_t
{
    APPROVED, DECLINED_INSUFFECIENT_FUND, DECLINED_STOLEN_CARD, INTERNAL_SERVER_ERROR
}EN_transState_t;

int main() {
ST_transaction_t account1 ;
return 0;
}

Now if did this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

typedef struct ST_transaction_t
{
    ST_cardData_t cardHolderData;
    ST_terminalData_t terminalData;
    //EN_transState_t transState;
    uint32_t transactionSequenceNumber;
}ST_transaction_t;
typedef enum EN_transState_t
{
    APPROVED, DECLINED_INSUFFECIENT_FUND, DECLINED_STOLEN_CARD, INTERNAL_SERVER_ERROR
}EN_transState_t;

int main() {
ST_transaction_t account1 ;
return 0;
}

It works perfectly, so why is that EN_transState_t transState causing that error and how to fix it ?

>Solution :

you problem is not about variable called EN_transState_t transState; itself, rather it’s about its typedef place in the code , I mean when the compiler compiles your code line by line and comes to this line EN_transState_t transState; , there is no previous declaration of such a type , as the declaration of such a type is mentioned in later lines meaning that EN_transState_t transState; comes before these lines:

   typedef enum EN_transState_t
   {
        APPROVED, DECLINED_INSUFFECIENT_FUND, DECLINED_STOLEN_CARD, INTERNAL_SERVER_ERROR 

    }EN_transState_t;

so you have to :

typedef enum EN_transState_t
{
    APPROVED, DECLINED_INSUFFECIENT_FUND, DECLINED_STOLEN_CARD, INTERNAL_SERVER_ERROR
}EN_transState_t;

typedef struct ST_transaction_t
{
    ST_cardData_t cardHolderData;
    ST_terminalData_t terminalData;
    EN_transState_t transState;
    uint32_t transactionSequenceNumber;
}ST_transaction_t;


int main() {
ST_transaction_t account1 ;
return 0;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading