C ++ has a method for this:
"constexpr" ++ 11, .
: return ( ), constexpr (++ 14 AFAIK).
static constexpr int foo(int x){
return x + 5;
}
EDIT:
( ):
, , , .
/ : , .
( , AVR), , , .
( ).
EDIT:
constexpr - , . constexpr, .
, , ?
inline , .
, constexpr . , constexpr , , .
, constexpr , inline .
constexpr int foo( int a, int b, int c ){
return a+b+c;
}
int array[ foo(1, 2, 3) ];
, .
struct Foo{
constexpr Foo( int a, int b, int c ) : val(a+b+c){}
int val;
};
constexpr Foo foo( 1,2,4 );
int array[ foo.val ];
foo.val - , .
, . , ( ).
, . , , .