R
Rick
Hi again,
I once saw that it was possible to define operators in C++ or something so I
was thinking, is it possible to store and use operators in C? For example,
first I read out a formula char by char. At some point I detect a operator
char ( + / - * ^ mod etc. ). After parsing the formula I want to use it as
quick as possible. So instead of reading that string again and again I'd
like to store all the functions/values and operators in structs or something
like that. I build this before in Visual Basic and when it came to the
execution of an operator I used something like this :
switch ( operator ) // operator is a field of a
struct( called type in VB )
case 0: output = input + x; // 0 stands for +
case 1: output = input - x; // 1 stands for minus
case 2: output = input * x;
case 3: output = input / x;
< etc. >
It worked well but maybe in C it could be faster by just doing :
output = input operator x;
The same thing for functions, while I'm now using
switch( function )
case 0: x = cos( x );
case 1: x = sin( x );
< and so on >
I'd like to store the function itself so I can directly use it like :
x = function( x );
Is this all possible?
Greetings,
Rick
I once saw that it was possible to define operators in C++ or something so I
was thinking, is it possible to store and use operators in C? For example,
first I read out a formula char by char. At some point I detect a operator
char ( + / - * ^ mod etc. ). After parsing the formula I want to use it as
quick as possible. So instead of reading that string again and again I'd
like to store all the functions/values and operators in structs or something
like that. I build this before in Visual Basic and when it came to the
execution of an operator I used something like this :
switch ( operator ) // operator is a field of a
struct( called type in VB )
case 0: output = input + x; // 0 stands for +
case 1: output = input - x; // 1 stands for minus
case 2: output = input * x;
case 3: output = input / x;
< etc. >
It worked well but maybe in C it could be faster by just doing :
output = input operator x;
The same thing for functions, while I'm now using
switch( function )
case 0: x = cos( x );
case 1: x = sin( x );
< and so on >
I'd like to store the function itself so I can directly use it like :
x = function( x );
Is this all possible?
Greetings,
Rick