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 6075003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:26:45+00:00 2026-05-23T10:26:45+00:00

I have looked up how to pass an enumeration in a function, but that

  • 0

I have looked up how to pass an enumeration in a function, but that method doesn’t work when both the function and enumeration are declared in a structure. Here is my code :

test_setup.h:

     1 #ifndef TEST_SETUP_H_
     2 #define TEST_SETUP_H_
     3 #include <stdio.h>
     4 #include <stdlib.h>
     5 
     6 
     7 typedef struct _test_setup {
     8 
     9   int *partner;            
    10   int *send_first;         
    11   double *results;         
    12 
    13   enum { CHIP_WIDE, NODE_WIDE, SYSTEM_WIDE } SomeMatches;
    14   void match_partners(SomeMatches match);
    15 
    16 } test_setup;              
    17 
    18 #endif

test_setup.c :

     1 #include "../includes/test_setup.h"
     2 
     3 void match_partners(SomeMatches match) { 
     4   if (match == CHIP_WIDE) {
     5 
     6   }
     7   else if (match == NODE_WIDE) {
     8 
     9   }
    10   else if (match == SYSTEM_WIDE) {
    11 
    12   }
    13   else {
    14 
    15   }
    16 }`

Error:

    In file included from src/test_setup.c:1:
    src/../includes/test_setup.h:14: error: expected ‘)’ before ‘match’
    src/../includes/test_setup.h:16: warning: no semicolon at end of struct or union
    src/test_setup.c:3: error: expected ‘)’ before ‘match’
    make: *** [setup.o] Error 1

I have tried every combination of declaring an enumeration and using it in the function parameters, but nothing has worked. Any ideas would be much appreciated. I am compiling with mpicc (because the rest of the program uses MPI functions) but I have tried with GNU GCC and I get the same warnings/errors.

  • 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-05-23T10:26:45+00:00Added an answer on May 23, 2026 at 10:26 am

    For C

    If you truly want C, then you simply can’t do any of this.

    • You can’t define a member function in a struct
    • You can’t define a named enumeration nested in a struct

    For C++

    Use the scope-resolution operator ::

    #include<iostream>
    
    struct Test
    {
      enum SomeEnum { TEST1, TEST2, TEST3 };
      void SomeFunction(SomeEnum e);
    };
    
    void Test::SomeFunction(Test::SomeEnum e)
    {
      std::cout << e << "\n";
    }
    
    int main(int argc, char* argv[])
    {
      Test t;
      t.SomeFunction(Test::TEST1);
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked at NHibernate and EntitySpaces and they both seem to work differently.
Hey all- I have looked this up on here and Google but none of
I have looked at most threads here about Doubly linked lists but still unclear
I have looked at few examples here Calling a Method from an Expression and
I have looked over the Repository pattern and I recognized some ideas that I
I have looked on FaceBook Developer page and found that it's possible to create
I have looked at the Suggested related questions but none of them are what
I have looked for a good example of a Builder pattern (in C#), but
I have the following PHP code that I can't seem to get working. I
I seem to be missing something quite fundamental here and yet my code doesn't

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.