struct cast

I don't understand bellow code.
Can you explain it (line 16 )? or share for me some material about it? What is it call?
Thanks all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include <iostream>
using namespace std;

typedef struct ACB{
   int text;
   int block;
}ACB_t;

typedef struct Context{
   void *text[3];
}Context_t;

int main(int args, char * argv[])
{
  Context *context= new Context();
  delete (ACB_t*)context->text[0];

return 0;
} 
Last edited on
delete (ACB_t*)context->text[0];
has three operators: ->, [], and C-style cast.

The -> and [] operators are evaluated before the cast because they have higher precedence.
The -> and [] have same precedence, and they are evaluated left to right, -> before [].

The context->text is an array of pointers.
The context->text[0] is the first element of the array. A pointer. Its type is void*. Uninitialized pointer.

The C-style cast converts void* into ACB*.


Overall, that code is brutal nonsense.
I dont understand why cast from struct Context to ACB is legal??
There is no cast from Context to ACB in that code.
I wrote:
The C-style cast converts void* into ACB*.
Topic archived. No new replies allowed.