|
在程序调试过程中出现这个问题,在指针传递的过程中,比如我想改变传递的实参的值。本来编译是没问题的,但现在我传递的是个结构体变量。如下:
先定义了个结构体
typedef struct
{
unsigned char year;
unsigned char month;
unsigned char date;
unsigned char hour;
unsigned char minute;
unsigned char day;
}clock;
static void Add_Chg_Sub(unsigned char *hr,unsigned char*min,unsigned char flg);
main()
{
unsigned char flg;
Add_Chg_Sub(&clock.hour,&clock.minute,flg);
}
static void Add_Chg_Sub(unsigned char *hr,unsigned char*min,unsigned charflg)
{
*hr += 1;
*min += 1;
}
如此编译无法通过,报错溢出。将函数static void Add_Chg_Sub(unsigned char *hr,unsigned char*min,unsigned char flg)改为
static void Add_Chg_Sub(unsigned char **hr,unsigned char**min,unsigned char flg),hr和min前面变为两个星号编译可通过,不知为何,现在操作的话改变的是否
还是clock.hour和clock.minute 的值? |
|