[Asterisk-Users] OT - C structure question

Rudolf Ladyzhenskii Rudolf.ladyzhenskii at opennw.com
Thu Feb 24 14:29:24 MST 2005


Hi,
This is something that I tought of BEFORE I had my morning cofee.

You can use array where your 'variable" points to an array element.

You can have array of 'void *'. In this case, an array element can point to anything.

for example:

int field1;
char *filed2;
struct MyData field3;

void * array[NUMBER_OF_ELEMENTS];

array[0] = (void *)&field1;
array[1] = (void *)field2;
array[2] = (void *)&field3;


Now you can have functions to select data:

int GetFiled1()
{
	return *((int *)array[0]);
}

char * GetFiled2()
{
	return (char *)array[1];
}

You got the idea.

Rudolf



-----Original Message-----
From: asterisk-users-bounces at lists.digium.com
[mailto:asterisk-users-bounces at lists.digium.com]On Behalf Of Asterisk
Sent: Friday, February 25, 2005 3:42 AM
To: asterisk-users at lists.digium.com
Subject: [Asterisk-Users] OT - C structure question


I hae tried searching the web for the answer, but, man is there a lot of 
    pages ... :(

in the language I develop in, if I have a structure I can dynamically 
refer to the contents of a field of the structure like so:

MESSAGE SomeStructure:Field(SomeFieldName):Value

where SomeFieldName is either a quoted constant or a variable expressions

In "C", I beleive that you can refer to the contents of a "field" in a 
"structure" like so:

chan->context or
chan->exten

Is is possible to refer to these fields like

chan->(variable) where variable is either "context" or "exten" or an 
expression that resolves to a valid fieldname of the structure ?

My reason for asking is that I want to create an application that would 
take a channel and a field name and return the value of the field.

for example

GetChannelData("context")
GetChannelData("exten")

and I didn't want to have to declare a massive case statement, and have 
to modify the app everytime some new fields were added to the structure.

I know that some of these variables are already exposed, but was wanting 
to get some other values.

Julian


_______________________________________________
Asterisk-Users mailing list
Asterisk-Users at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users



More information about the asterisk-users mailing list