#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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\n",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\n",sizeof(my_asoc_dai));
// strcpy(my_asoc_dai.name,"I2S"); // 变量的操作
// printf("my_asoc_dai.name is %s\n",my_asoc_dai.name);
my_asoc_dai.name = "I2S"; //
printf("my_asoc_dai.name is %s\n",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\n",my_asoc_dai.tx_slot_mask);
printf("my_amy_asoc_dai.rx_slot_mask is %d\n",my_asoc_dai.rx_slot_mask);
set_asoc_param_value(my_asoc_dai);//值传递的坑
printf("my_asoc_dai.tx_slot_mask 22222is %d\n",my_asoc_dai.tx_slot_mask);
printf("my_amy_asoc_dai.rx_slot_mask 2222is %d\n",my_asoc_dai.rx_slot_mask);
for(;;);
return 0;
}
原文:https://www.cnblogs.com/nowroot/p/13703584.html