开发者

What is this line doing in the thread safe build of PHP?

I was reading the book Extending and Embedding PHP and came across this line in C (with related structures):

typedef struct {
    int sampleint;
    char *samplestring;
} php_sample_globals;
int sample_globals_id;

开发者_运维知识库(((php_sample_globals*)(*((void ***)tsrm_ls))[sample_globals_id - 1])->sampleint = 5

The author then writes:

"Don't be concerned if you have trouble parsing that statement; it's so well integrated into the PHPAPI that some developers never bother to learn how it works."

I start to get lost around *((void ***)tsrm_ls)


*((void ***)tsrm_ls)

Cast the variable tsrm_ls as a pointer to a pointer to a pointer and then get what is pointed to (thus you end up with a pointer to a pointer)

Looking at the rest of the code and assuming it is correct:

tsrm_ls is a pointer to an array of pointers to php_sample_globals structures.

This code looks at the sample_globals_id-1 index into that array finds the structure it points to and then sets the sampleint element of that structure to 5

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜