Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:08:01+00:00 2026-06-14T17:08:01+00:00

I have a program that needs two different values of the same variable depending

  • 0

I have a program that needs two different values of the same variable depending on the state of the program.

Function is declared in header (test.inc):

void function_a(int pr)
{
    if (pr == 1)
    enum{
      a = 5,
      b = 5,
      c = 5,
    };
    else
    enum{
      a = 2,
      b = 2,
      c = 2,
    };
}

And program: (main.c)

int main() {
    function_a(1);        
    printf("%d",a);
    return (EXIT_SUCCESS);
}

After compiling it say:

main.c:26: error: `a’ undeclared (first use in this function)
main.c:26: error: (Each undeclared identifier is reported only once
main.c:26: error: for each function it appears in.)

How to make a global declaration using enum in function located in header?
Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:08:03+00:00Added an answer on June 14, 2026 at 5:08 pm

    There’s no use for an enum here, you just need 3 global variables and set those:

    int a,b,c;
    
    void function_a(int pr)
    {
        if (pr == 1) {
          a = 5,
          b = 5,
          c = 5,
        } else {
          a = 2;
          b = 2;
          c = 2;
        }
    }
    
    int main() {
        function_a(1);        
        printf("%d",a);
        return (EXIT_SUCCESS);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# program that selects data from two different database files and
I need an XML-serializable dictionary. Actually, I now have two quite different programs that
I have a program that needs to... In Activity A , do some jobs
I have a program that needs several third-party libraries, and at the moment it
I have a program that needs a lot of memory and want to set
I have a Flash program that needs to make url requests to send data
In an embedded program I have a screen object that needs to manage a
I have a SQL Server table full of orders that my program needs to
I have a program (process) which needs to listen on 3 ports... Two are
I have a table with unique values. The problem is that the program, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.