M
Milux
Hi All,
This question has to do with interface design. Suppose I have an translation
tool. It can translates structs from type "general" to other types and then
does some processing.
Example:
typedef struct
{
int data1;
int data2;
}general;
typedef struct
{
int data3;
}specific_a;
For example, the translation looks like this:
void translate1(general * input)
{
specific_a * new_specific_a = malloc (.....);
new_specific_a->data3 = input->data1 * input->data2;
/* use here new_specific_a for a while */
}
Suppose have another type:
typedef struct
{
int data4;
int data5;
}specific_b;
In this specific case another translation looks like:
void translate2(general * input)
{
specific_b * new_specific_b = malloc(....);
new_specific_b->data4 = input->data1;
new_specific_b->data5 = input->data2;
/* do some processing with new_specific_b */
}
Because other interfaces are fixed I need type "specific_a" in the
"translate1" method and "specific_b" in "translate2".
I see an optimalization here in the translate2 method, namely:
void translate2(general * input)
{
specific_b * new_specific_b = (specific_b *) input;
}
(Note: I use the structures specific_b and specific_a only for reading).
Instead of generating the new message, I want to cast the struct (because in
this specific case the data items match exactly). Is this allowed?? In other
words, returns a call to new_specific_b->data4 return data1 and
new_specific_b->data5 return data2 or are there some compiler issues to take
keep in mind?
Grz Milux
This question has to do with interface design. Suppose I have an translation
tool. It can translates structs from type "general" to other types and then
does some processing.
Example:
typedef struct
{
int data1;
int data2;
}general;
typedef struct
{
int data3;
}specific_a;
For example, the translation looks like this:
void translate1(general * input)
{
specific_a * new_specific_a = malloc (.....);
new_specific_a->data3 = input->data1 * input->data2;
/* use here new_specific_a for a while */
}
Suppose have another type:
typedef struct
{
int data4;
int data5;
}specific_b;
In this specific case another translation looks like:
void translate2(general * input)
{
specific_b * new_specific_b = malloc(....);
new_specific_b->data4 = input->data1;
new_specific_b->data5 = input->data2;
/* do some processing with new_specific_b */
}
Because other interfaces are fixed I need type "specific_a" in the
"translate1" method and "specific_b" in "translate2".
I see an optimalization here in the translate2 method, namely:
void translate2(general * input)
{
specific_b * new_specific_b = (specific_b *) input;
}
(Note: I use the structures specific_b and specific_a only for reading).
Instead of generating the new message, I want to cast the struct (because in
this specific case the data items match exactly). Is this allowed?? In other
words, returns a call to new_specific_b->data4 return data1 and
new_specific_b->data5 return data2 or are there some compiler issues to take
keep in mind?
Grz Milux