Sign in to follow this  
raptorstrike

assigning a member expression

Recommended Posts

ok what i want to know is if there is a way to give a function a statement as a parameter for example (X>9) it will probibly have to take the form of a string but as long as i can convert it back in the end thats fine edit: or even to give it some kind varable or pointer would be fine too edit2: basicaly i want to know if there is a way to treat a compound expression as a single entity

Share this post


Link to post
Share on other sites
Its fairly simple in scheme for example, but a bit more complex in C/C++/Java.

If you had to do it in C/C++ use the three dots and parse your input yourself, for example:


void complexExpresion(...){
//look up va stuff to learn how to use the three dots
va_list ap;
va_start(ap, fmt);
va_end(ap);
}






Anyway I copied this from a book for you:


statically typed language:
A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring
you to declare all variables with their datatypes before using them. Java and C are statically typed languages.

dynamically typed language:
A language in which types are discovered at execution time; the opposite of statically typed. VBScript and
Python are dynamically typed, because they figure out what type a variable is when you first assign it a value.

strongly typed language:
A language in which types are always enforced. Java and Python are strongly typed. If you have an integer,
you can't treat it like a string without explicitly converting it.

weakly typed language:
A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In
VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as
the integer 123, all without any explicit conversion.

Share this post


Link to post
Share on other sites
Probably the easiest way to do that is to use a function pointer. You can pass around pointers to functions just like any other pointer, though the syntax for declaring a function pointer type can be a bit messy. Here is an example I found in MSDN using qsort. You pass the function's pointer as an argument of a function by simply using the function's name without following it with parenthesis.

Function Declaration:

void qsort(
void *base,
size_t num,
size_t width,
//Function pointer parameter declaration:
int (__cdecl *compare )(const void *, const void *)
);

Example of Use:

int compare( const void *arg1, const void *arg2 );

void main( int argc, char **argv )
{
int i;
/* Eliminate argv[0] from sort: */
argv++;
argc--;

/* Sort remaining args using Quicksort algorithm: */
qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare ); /*see, the function 'compare' is being passed as an argument.*/

/* Output sorted list: */
for( i = 0; i < argc; ++i )
printf( "%s ", argv[i] );
printf( "\n" );
}

int compare( const void *arg1, const void *arg2 )
{
/* Compare all of both strings: */
return _stricmp( * ( char** ) arg1, * ( char** ) arg2 );
}

Share this post


Link to post
Share on other sites
In what language? In many scripting languages, and dynamic programming languages, you have closures. In C or C++, you have to use various work-arounds to provide almost-closures, such as functor objects with overloaded function call operators or whatnot.

Share this post


Link to post
Share on other sites
Quote:
Original post by raptorstrike
all i get when surching for VA is people who live in vermont lol is there another name i could find it under?



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_va_arg.2c_.va_end.2c_.va_start.asp

Share this post


Link to post
Share on other sites
either what you guys are saying applys to me and im just not getting it or you missinterpret my question so ill state it one more time

is there a way to imput an equation into a function like:

solve(X > 1 - 2)
or to store it in a variable
expression_holder A = (X + 1 -2/2)
not what it equals because that will depend on the varable past at run time but just the equation thanks again [smile]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this