Please refer to the ILE C/C++ Programmer's Guide. In the 'Coding a C++ Program" section, look at the example code for the inline keyword. Note that the inline prototype is the expanded function; there is no function defined further down in the code. Please try changing your code to

// Prototypes

static inline int add_value(int x, int y)
{
return x + y;
};


int main(int argc, char **argv)
{
int returnValue = 0;

int x = 2;
int y = 0;

int z = add_value(x, y);

return returnValue;

}

There is also the possibility that the static declaration with the inline is confusing the compiler. Technically, the function cannot be both static and inline as static sets aside space at compile/link time whereas inline inserts the inlined function into the source code at compile time.

Finally, try removing the semicolon from the end of the function as in

static inline int add_value(int x, int y)
{
return x + y;
}; <==

I've seen this result in errors with other compilers. It is needed as I've shown above - where the definition is included in the prototype section, but not otherwise. Your code would become:


// Prototypes
int add_value(int x, int y);

int main(int argc, char **argv)
{
int returnValue = 0;

int x = 2;
int y = 0;

int z = add_value(x, y);

return returnValue;
}

static inline int add_value(int x, int y)
{
return x + y;
} /* <== The semicolon is removed */

Regards,
Mike


Schmidt, Mihael wrote:
Hi,

I got a little problem with inlining a function in the following example code:


// Prototypes
int add_value(int x, int y);


int main(int argc, char **argv)
{
int returnValue = 0;

int x = 2;
int y = 0;

int z = add_value(x, y);

return returnValue;

}

static inline int add_value(int x, int y)
{
return x + y;
};
If i try to compile this I get:


This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact [javascript protected email address].