zoukankan      html  css  js  c++  java
  • C语言结构体类型的typedef和结构体变量的初始化和函数传递地址传递和结构体变量的相关操作

    #include <stdio.h>
    #include <stdlib.h>
    #include <limits.h>
    #include <time.h>
    #include <pthread.h>
    #include <semaphore.h>
    #include <unistd.h>
    #include <signal.h>
    #include <string.h>
    #include <stdlib.h>
    
    struct asoc_simple_dai {   //只是一个框架  不会分配空间
    	const char *name;  // 数据类型 +属性名
    	unsigned int sysclk;
    	int slots;
    	int slot_width;
    	unsigned int tx_slot_mask;
    	unsigned int rx_slot_mask;
    };
    
    // typedef 类型名  xxx;
    typedef struct asoc_simple_dai  asoc_simple_dai_T;
    asoc_simple_dai_T my_asoc_dai;// 变量的定义和初始化
    
    
    //地址传递
    static void  get_asoc_name(asoc_simple_dai_T* asoc_simple_dai111)
    {
        if(asoc_simple_dai111 == NULL)
        {
            return ;
        }
        printf("asoc_simple_dai111 %s
    ",asoc_simple_dai111->name);
    }
    
    // 地址传递
    static void  set_asoc_param(asoc_simple_dai_T* asoc_simple_dai111)
    {
        if(asoc_simple_dai111 == NULL)
        {
            return ;
        }
        asoc_simple_dai111->rx_slot_mask = 0xff;
        asoc_simple_dai111->tx_slot_mask = 0xff;
    }
    
    // 值传递   耗内存 //
    static void  set_asoc_param_value(asoc_simple_dai_T  asoc_simple_dai111)
    {
        asoc_simple_dai111.tx_slot_mask = 0x01;
        asoc_simple_dai111.rx_slot_mask = 0x03;
    }
    
    int main()
    {
    
        printf("%d
    ",sizeof(my_asoc_dai));
       // strcpy(my_asoc_dai.name,"I2S"); // 变量的操作
       // printf("my_asoc_dai.name is %s
    ",my_asoc_dai.name);
        my_asoc_dai.name = "I2S";  //
        printf("my_asoc_dai.name is %s
    ",my_asoc_dai.name);
        my_asoc_dai.rx_slot_mask = 0x01;
        my_asoc_dai.tx_slot_mask = 0x02;
        my_asoc_dai.slots = 1;
        my_asoc_dai.slot_width = 0x01;
        get_asoc_name(&my_asoc_dai);
        set_asoc_param(&my_asoc_dai);
        printf("my_asoc_dai.tx_slot_mask is %d
    ",my_asoc_dai.tx_slot_mask);
        printf("my_amy_asoc_dai.rx_slot_mask is %d
    ",my_asoc_dai.rx_slot_mask);
        set_asoc_param_value(my_asoc_dai);//值传递的坑
        printf("my_asoc_dai.tx_slot_mask 22222is %d
    ",my_asoc_dai.tx_slot_mask);
        printf("my_amy_asoc_dai.rx_slot_mask 2222is %d
    ",my_asoc_dai.rx_slot_mask);
    
        for(;;);
        return 0;
    }
    

      

    一勤天下无难事。
  • 相关阅读:
    Python3 CGI编程实现教程
    SSL密钥协商过程分析
    浏览器同源策略理解
    Python3+selenium 报错处理:“selenium.common.exceptions.NoAlertPresentException: Message: No alert is active”
    Python3 try-except、raise和assert解析
    计算机视觉常见技术(待理解)
    中国大学MOOC-陈越、何钦铭-数据结构-2017春
    Coursera机器学习+deeplearning.ai+斯坦福CS231n
    总结一些机器视觉库
    git rebase 多分支操作
  • 原文地址:https://www.cnblogs.com/nowroot/p/13703584.html
Copyright © 2011-2022 走看看