Ask about error when declare "static inline int"

This is a discussion on Ask about error when declare "static inline int" within the C Programming forums, part of the General Programming Boards category; When I compile source code. There are this below error. Do you know how to solve this problem? Thank you. ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Cool Ask about error when declare "static inline int"

    When I compile source code. There are this below error. Do you know how to solve this problem? Thank you.

    Code

    static inline int modnn(struct rs *rs,int x){
    while (x >= rs->nn) {
    x -= rs->nn;
    x = (x >> rs->mm) + (x & rs->nn);
    }
    return x;
    }


    Compiling...
    rs.c
    e:\char.h(22) : error C2054: expected '(' to follow 'inline'
    e:\char.h(22) : error C2085: 'modnn' : not in formal parameter list
    e:\char.h(22) : error C2143: syntax error : missing ';' before '{'

    Error executing cl.exe.

    rs.exe - 3 error(s), 13 warning(s)

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    What compiler are you using? I'm using GCC 3.03 on Win98 and it works.

    I've used this little code to compile.

    Code:
    struct rs
    {
        int mm;
        int nn;
    };
    
    static inline int modnn (struct rs *rs,int x)
    { 
        while (x >= rs->nn) { 
            x -= rs->nn; 
            x = (x >> rs->mm) + (x & rs->nn); 
        } 
        return x; 
    } 
    
    int main() 
    {
        return 0; 
    }

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I believe you'll find the inline keyword is for C++. That's what my compiler says anyways!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You both probably have a compiler which doesn't support the latest C standard, that standard introduced inline functions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When to inline your *tors
    By Angus in forum C++ Programming
    Replies: 43
    Last Post: 10-29-2008, 04:38 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. Inline functions and inheritance
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2004, 06:46 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. bit shifting
    By Nor in forum C++ Programming
    Replies: 9
    Last Post: 08-08-2003, 12:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21