理解C结构
我试图了解以下C结构中发生了什么:理解C结构,c,pointers,struct,function-pointers,forward-declaration,C,Pointers,Struct,Function Pointers,Forward Declaration,我试图了解以下C结构中发生了什么: /* EXCERPT from LINES 59-90 */ /* parse.h * Copyright (c) 2011, Peter Ohler * All rights reserved. */ typedef struct _ParseInfo { // used for the string parser const char *json; const char *cur; const c
/* EXCERPT from LINES 59-90 */
/* parse.h
* Copyright (c) 2011, Peter Ohler
* All rights reserved.
*/
typedef struct _ParseInfo {
// used for the string parser
const char *json;
const char *cur;
const char *end;
// used for the stream parser
struct _Reader rd;
struct _Err err;
struct _Options options;
VALUE handler;
struct _ValStack stack;
CircArray circ_array;
int expect_value;
VALUE proc;
VALUE (*start_hash)(struct _ParseInfo *pi);
void (*end_hash)(struct _ParseInfo *pi);
VALUE (*hash_key)(struct _ParseInfo *pi, const char *key, size_t klen);
void (*hash_set_cstr)(struct _ParseInfo *pi, Val kval, const char *str, size_t len, const char *orig);
void (*hash_set_num)(struct _ParseInfo *pi, Val kval, NumInfo ni);
void (*hash_set_value)(struct _ParseInfo *pi, Val kval, VALUE value);
VALUE (*start_array)(struct _ParseInfo *pi);
void (*end_array)(struct _ParseInfo *pi);
void (*array_append_cstr)(struct _ParseInfo *pi, const char *str, size_t len, const char *orig);
void (*array_append_num)(struct _ParseInfo *pi, NumInfo ni);
void (*array_append_value)(struct _ParseInfo *pi, VALUE value);
void (*add_cstr)(struct _ParseInfo *pi, const char *str, size_t len, const char *orig);
void (*add_num)(struct _ParseInfo *pi, NumInfo ni);
void (*add_value)(struct _ParseInfo *pi, VALUE val);
} *ParseInfo;
发件人:
我不明白第74行(上面清单中的第22行)发生了什么
首先是:
VALUE (*start_hash)(struct _ParseInfo *pi);
有人能解释一下这些行在做什么吗?它们是,语法是:返回类型(*pointer\u name)(args)
然而,开发人员使用的是一种特殊技术,由第一个参数表示,它总是指向\u解析器
结构的指针。它确实允许一种简单的面向对象编程形式,其中类可以有方法专门作用于某个必须手动设置和处理的对象实例。@paxdiablo的精彩答案中有更多信息
注意:存在多个违反ISO C的情况,因为您不允许在名称前面加上
\uu
和大写名称。更多信息。这些是函数指针声明。把代码贴在这里。链接会随着时间的推移而失效。这不是他的代码,这是版权。这并不严格。我要编辑。