Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know whether a pointer points to a specific structure or not?

Tags:

c

pointers

struct

For example, in Linux, I have a pointer pointing to a task_struct. Later, the task_struct might migrate or deleted. How do I know whether the pointer still points to a task_struct or not?

like image 411
Hao Shen Avatar asked Dec 07 '22 12:12

Hao Shen


1 Answers

It's not possible.

Pointers only contain addresses, and generally it's not possible to determine whether or not a given address is "valid".

Sometimes you can ask the entity that gave you the pointer to begin with if it's still valid, but that of course depends on the exact details of the entity. The language itself cannot do this.

like image 113
unwind Avatar answered Dec 28 '22 22:12

unwind