指向指针的指针, *((key_type**)数据获取

今天看CSR ADK2.5.1一段代码, 获取一组pskey数据, 使用了有点点绕的指针数据结构, 来分析下:

  1. 先上获取一个数据的通用表达式. 分析的目的就是如何获取这个表达式
key_type * key;
key = *((key_type**)default_configs[config_id] + key_id);
  1. default_configs的定义:
/* Table of default configurations */
const config_type* const default_configs[] = 
{  
    /* CSR Sink Stereo */
     &csr_stereo_default_config,
    /* CSR Sink Mono */ 
     &csr_mono_default_config,
    /* CSR Car Kit */ 
     &csr_car_default_config,
     0,
...
    0
};
  1. config_type的定义:
typedef struct
{
     const key_type*      battery_config;             /* PSKEY_USR_0 - Battery configuration */
     const key_type*      button_config;                 /* PSKEY_USR_1 - Button configuration */
     const key_type*     button_pattern_config;      /* PSKEY_USR_2 - Button Sequence Patterns*/
    const key_type*      supported_features_config;    /* PSKEY_USR_3 - HFP supported features block */
...
    const key_type*      soundbar_hid_remote_conf;    /* PSKEY_USR_33 - soundbar HID remote control */
     
} config_type;
  1. csr_stereo_default_config的定义:
/* Default Configuration */
const config_type csr_stereo_default_config = 
{
     (key_type *)&battery_config,            /* PSKEY_USR_0 - Battery configuration */
      (key_type *)&button_config,               /* PSKEY_USR_1 - Button configuration */
      (key_type *)&button_pattern_config,        /* PSKEY_USR_2 - */
      (key_type *)&at_commands,               /* PSKEY_USR_3 - AT Commands*/
      (key_type *)&pio_block,                    /* PSKEY_USR_4 - Input/output pio block*/
      (key_type *)&HFP_features_config,        /* PSKEY_USR_5 - The HFP Supported features*/
      (key_type *)&timeouts,                     /* PSKEY_USR_6 - Timeouts*/
      (key_type *)&tri_col_leds,                 /* PSKEY_USR_7 - Tri Colour LEDS */
      (key_type *)&deviceId_Info,             /* PSKEY_USR_8 - Device Id information*/
      (key_type *)&lengths,                   /* PSKEY_USR_9 - length of tts, led filter, led states, led events, tones*/
...
    (key_type *)&soundbar_hid_remote_conf   /* PSKEY_USR_33 - Soundbar HID remote configuration */   
}
  1. 如开篇问题, 为何第一个数据获取方法是key =*((key_type**)default_configs[0] );
    分析:
    (1) default_configs[0]即&csr_stereo_default_config,它是一個config_type指針,即一個config_type結構的首地址,
    這個地址同時也是其第一個元素battery_config的地址,,也就是説如果對它進行*運算,得到的當然就是battery_config的内容了。
    battery_config的内容是什麽呢?就是一個key_type*,其地址當然是key_type**,所以爲了類型正確,先做一個key_type **轉換。
    (2) battery_config的地址可表示为
    (key_type**)(default_configs[0])
    对这个数据取值, 就是 *((key_type**)default_configs[config_id]);
    对某个pskey取值, 当然是*((key_type**)default_configs[config_id] + key_id);
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值