Thread: Passing argument to function enumerator that is member of a struct

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    97

    Passing argument to function enumerator that is member of a struct

    Hi everyone,

    I will to explain as clear as I can..

    I have an enum inside a struct like this below in a seperate file than .c (the struct has many members, just for simplicity I added one now):

    Code:
    struct bmi160_int_settg
    {
        /*! Select Interrupt */
        enum bmi160_int_types int_type;
    };
    Code:
    enum bmi160_int_types {
        /*! Slope/Any-motion interrupt */
        BMI160_ACC_ANY_MOTION_INT,
    
    
        /*! Significant motion interrupt */
        BMI160_ACC_SIG_MOTION_INT,
    
    
        /*! Step detector interrupt */
        BMI160_STEP_DETECT_INT
    };
    Now, in the main.c I want to write a function which will take as parameter a member from the enun bmi160_int_types e.g BMI160_ACC_ANY_MOTION_INT. The function declaration will be in a seperate .h file

    How should I decalre the function and how should I call it?

    Thanks in advance
    Nick

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Like so
    Code:
    void some_function( enum bmi160_int_types a_value );
    
    
    ///
    
    
    int main ( ) {
        some_function(BMI160_ACC_ANY_MOTION_INT);
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    97
    I will try thanks!!

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    97
    Quote Originally Posted by Salem View Post
    Like so
    Code:
    void some_function( enum bmi160_int_types a_value );
    
    
    ///
    
    
    int main ( ) {
        some_function(BMI160_ACC_ANY_MOTION_INT);
    }

    It works fine, thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting by passing struct as argument
    By ymc1g11 in forum C Programming
    Replies: 2
    Last Post: 11-01-2012, 03:58 PM
  2. Calling argument of member function
    By davewang in forum C++ Programming
    Replies: 3
    Last Post: 02-26-2010, 01:51 PM
  3. Passing member variable as default arg to member function
    By Memloop in forum C++ Programming
    Replies: 1
    Last Post: 09-08-2009, 06:49 PM
  4. returning struct and passing as an argument
    By ronin in forum C Programming
    Replies: 4
    Last Post: 06-07-2003, 11:21 AM
  5. passing struct member to function
    By Sargnagel in forum C Programming
    Replies: 2
    Last Post: 01-06-2003, 05:55 PM

Tags for this Thread