Linked by Owen Anderson on Mon 19th Apr 2004 05:43 UTC
General Development For years the development scene has been dominated by the C family of languages, primarily C itself and its immediate successor C++. Recent years have given rise to other C-descendents, however, such as Sun's Java and Microsoft's C#.
Permalink for comment
To read all comments associated with this story, please click here.
re: What is your sample supposed to show ?
by pete on Tue 20th Apr 2004 15:46 UTC

This should make my meaning more clear :

/************************************
EXAMPLE FUNCTION: func_any

this function is purely theoretical
and will not work in the context
of any current programming language.

The function demostrates a
programmatic action based on the data
type input to a function.

The current equivalent to 'anytype'
is 'void *' but void * requires a
type cast to other pointer types.

ie:

typedef union __variable_pointer
{
void *pv;
int *pi;
char *pc;
unsigned short *pus;
float *pf;
double *pd;
}VARIABLE_POINTER;

typedef struct __a_variable
{
unsigned long var_type;
unsigned long size;
void *storage;
VARIABLE_POINTER data;
/* data.pv should always == A_VARIABLE.storage */
}A_VARIABLE;


************************************/

anytype func_any(anytype a)
{
anytype b;//this variable type is defined as it is created

if(typeof(a)==int)//a is int
{
b=new int[4];//allocate an int array
return b;//return the array
}


if(typeof(a)==char) // a is char
{
b=new char[4];//allocate a char array
return b;//return the array
}

switch(typeof(a))
{
case double: //a is double
b=new double[4];//allocate a double array
return b;//return the array
break;
case float://a is float
b=new float[4];//allocate a float array
return b;//return the array
break;
default:
return NULL;//possible undefined type
}/*end switch typeof(a)*/


} /* END func_any*/



pete