• C的魅力在于指针


    在这里插入图片描述

    在这里插入图片描述

    原有的adrv9025 代理框架很好用,在其原有的平台上做改进

    char ***rows = calloc(16, sizeof(char *));
      for (int32_t i = 0; i < 16; i++) {
        rows[i] = calloc(sizeof(char *), 10);
        for (int32_t j = 0; j < 11; j++) {
          rows[i][j] = calloc(1, 128);
          sprintf(rows[i][j], "Hello World");
        }
      }
      for (int32_t i = 0; i < 16; i++) {
        printf("row:%d ", i);
        for (int32_t j = 0; j < 11; j++) {
          printf("[col:%d %s] ", j, rows[i][j]);
        }
        printf("\n");
      }
      return 0;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    字符串 分成行列

    在这里插入图片描述

    指针存储地址,指针本身的大小,和几级指针没有关系,不同类型的指针,只是方便形成数组时,自动按照字长,分割出来

    /*example override stmt cache functions*/
    static inline int32_t __attribute__((__unused__))
    stmt2cache(struct sqlite3_stmt *stmt, struct cacheList *node) {
      struct cache *pnode = container_of(&node, struct cache, list);
      if (pnode == 0 || node == 0) {
        return -1;
      }
      node->para.id.u32 =
          (uint32_t)strtol((const char *)sqlite3_column_text(stmt, 0), 0, 16);
      memcpy(node->para.name, (const char *)sqlite3_column_text(stmt, 1),
             strlen((const char *)sqlite3_column_text(stmt, 1)));
      memcpy(node->para.mode, (const char *)sqlite3_column_text(stmt, 2),
             strlen((const char *)sqlite3_column_text(stmt, 3)));
      memcpy(node->para.type, (const char *)sqlite3_column_text(stmt, 3),
             strlen((const char *)sqlite3_column_text(stmt, 3)));
      node->para.coef = (float)sqlite3_column_double(stmt, 4);
      node->para.len = (uint32_t)sqlite3_column_int(stmt, 5);
      memcpy(node->para.value, (const char *)sqlite3_column_text(stmt, 6),
             strlen((const char *)sqlite3_column_text(stmt, 6)));
      node->para.attr = (uint8_t)sqlite3_column_int(stmt, 9);
      return 0;
    }
    
    // Only For MCPA
    static inline int32_t __attribute__((__unused__))
    serdes2str(char *buf, struct cache2para *ca) {
      if (buf == 0 || ca == 0) {
        return -2;
      }
      bzero(buf, strlen(buf));
      sprintf(buf, "\"0x%04X\",\"%s\",\"%s\",\"%s\",%f,%d,\"%s\",%d,%d,%d",
              ca->id.u32, ca->name, ca->mode, ca->type, ca->coef, ca->len,
              ca->value, ca->minThrehold, ca->maxThrehold, ca->attr);
      return 0;
    }
    
    static inline int32_t __attribute__((__unused__))
    stmt_common(struct sqlite3_stmt *stmt, void *args) {
      struct cacheList *newNode = ((struct cache *)args)->list;
      struct LIST_NODE *root = &((struct cache *)args)->root;
      struct cache *_cache = (struct cache *)args;
      newNode = (struct cacheList *)calloc(sizeof(struct cacheList), 1);
      if (newNode == 0) {
        return -2;
      }
      newNode->serdes2str = _cache->serdes2str4cacheList;
      _cache->deserdes2stmt4list(stmt, newNode);
      list_add_tail(&newNode->node, root);
      return 0;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    int32_t Example(void) {
      static struct SQLITE3_BASE_INFO rmu_db = {.db_path =
                                                    "/mnt/flash/config/drurmu.db"};
    
      static struct SQLITE3_DEV rmu_dev = {.info = &rmu_db};
      static struct cache CACHE[] = {{.cacheName = "MCPC 32bit IDX",
                                      .dev = &rmu_dev,
                                      .db_table = "rmu",
                                      .updateValueName = "V0",
                                      .indexType = "str2hex16bitBIG",
                                      .root = {&CACHE[0].root, &CACHE[0].root},
                                      .deserdes2stmt4list = stmt2cache,
                                      .serdes2str4cacheList = serdes2str}};
    
      for (int32_t i = 0; i < ARRAY_SIZE(CACHE); i++) {
        if (SQLITE3_OPEN(CACHE[i].dev) == -9) {
          printf("%s\n", CACHE[i].dev->errMsg);
          return 0;
        }
        if (SQLITE3_DESERDES_TABLE(CACHE[i].dev, CACHE[i].db_table, stmt_common,
                                   &CACHE[i])) {
          printf("error:%s\n", sqlite3_errmsg(CACHE[i].dev->handle));
        }
      }
      const struct cacheList *cur = 0;
      for (int32_t i = 0; i < 0xFFFF; i++) {
        cur = cacheSectionSearch(&CACHE[0], i);
        if (cur == 0) {
          continue;
        }
        printf("index:%08x name:%s value:%s %s\n", i, cur->para.name,
               cur->para.value, CACHE[0].indexType);
        if (cacheSectionUpdate(&CACHE[0], i, "hello world") < 0) {
          printf("update error:%s \n", sqlite3_errmsg(CACHE[0].dev->handle));
        }
        cur = cacheSectionSearch(&CACHE[0], i);
        printf("index:%08x name:%s value:%s\n", i, cur->para.name, cur->para.value);
      }
      cacheSectionDelete(&CACHE[0], 0x2);
      struct cacheList *insertList = newcacheList(0x2, "HelloInsertMode", "RW", "1",
                                                  "data", 1.0, 1, serdes2str);
      cacheSectionPush(&CACHE[0], insertList);
      return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
  • 相关阅读:
    Runable和Callable的区别?首先要搞清楚Thread以及FutureTask!
    【WALT】WALT入口 update_task_ravg() 代码详解
    C++ 多维数组
    跨语言深入探讨如何实现方法增强:Java & Go的多策略实现
    (附源码)springboot教学评价 毕业设计 641310
    笔记本电脑查询连接wifi密码
    轻松学习Python:基础知识汇总
    QSqlRelationTableModel使用示例
    Linux之Nignx及负载均衡&动静分离
    实验30:避障传感器实验
  • 原文地址:https://blog.csdn.net/weixin_45647912/article/details/133937336