性无码一区二区三区在线观看,少妇被爽到高潮在线观看,午夜精品一区二区三区,无码中文字幕人妻在线一区二区三区,无码精品国产一区二区三区免费

  • 回復(fù)
  • 收藏
  • 點贊
  • 分享
  • 發(fā)新帖

用函數(shù)指針傳送數(shù)組指針變量的問題

最近在用AT89S52+12864LCD顯示菜單時用到函數(shù)指針,想用函數(shù)指針調(diào)用不同函數(shù),同時調(diào)用不同的數(shù)組,所以寫了個例子,只要能實現(xiàn)功能.可是例中加!!!的地方就是編釋不過,手上的資料又少,望高手指點一二!!在此謝過.
全部回復(fù)(10)
正序查看
倒序查看
xing1234
LV.6
2
2008-01-12 11:55
#include
#include
#include
#include
unsigned char  tongdata[12];
write_at2401(unsigned char a,unsigned char b,unsigned char c)
{
a=0;
b=0;
c=0;
}
void tong_gao(unsigned char chao,unsigned char max,unsigned char da,unsigned char *b)//
{
  unsigned char id;
  id=*(b+da);
if(chao>max)   
chao=0;  
write_at2401(0xA0,da,id);
chao=1;
}
/*****************主程序區(qū)****************************/
main()
{
  unsigned char      chao,chu,max,*se_data;
void (*p)(unsigned char ,unsigned char ,unsigned char ,unsigned char);
// void tong_gao(unsigned char ,unsigned char ,unsigned char ,unsigned char *);
chao=5;
chu=10;
max=12;
  p=tong_gao;
  se_data=tongdata;
  (*p)(chu,max,chao,se_data);//!!!!!!!!!!!!!!!!!!!!!!!!!
}
0
回復(fù)
xing1234
LV.6
3
2008-01-12 11:58
@xing1234
#include#include#include#includeunsignedchar  tongdata[12];write_at2401(unsignedchara,unsignedcharb,unsignedcharc){a=0;b=0;c=0;}voidtong_gao(unsignedcharchao,unsignedcharmax,unsignedcharda,unsignedchar*b)//{  unsignedcharid;  id=*(b+da);if(chao>max)  chao=0;  write_at2401(0xA0,da,id);chao=1;}/*****************主程序區(qū)****************************/main(){  unsignedchar      chao,chu,max,*se_data;void(*p)(unsignedchar,unsignedchar,unsignedchar,unsignedchar);//voidtong_gao(unsignedchar,unsignedchar,unsignedchar,unsignedchar*);chao=5;chu=10;max=12;  p=tong_gao;  se_data=tongdata;  (*p)(chu,max,chao,se_data);//!!!!!!!!!!!!!!!!!!!!!!!!!}
error C212: indirect call: parameters do not fit within registers
0
回復(fù)
2008-01-13 21:57
@xing1234
errorC212:indirectcall:parametersdonotfitwithinregisters
學(xué)習(xí)一下,怎么弄這個.是返回一個指針嗎?還看不懂.返回指針,得賦值的吧?

我就會指針參數(shù),往函數(shù)外輸.
0
回復(fù)
xing1234
LV.6
5
2008-01-14 08:50
我的目的:
1、將變量chu,max,chao和指向數(shù)組tongdata[12]的數(shù)組指針變量se_data,通過函數(shù)指針p傳到p指向的函數(shù)tong_gao;
2、通過改變數(shù)組指針變量se_data和函數(shù)指針p,我可以將不同的數(shù)組傳送到不同的函數(shù)進行類似的運算.
0
回復(fù)
whatcall
LV.5
6
2008-01-14 09:13
@xing1234
errorC212:indirectcall:parametersdonotfitwithinregisters
參考:http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/566020.html
(*p)和tong_gao最后一個傳遞參數(shù)類型不一致,一個是unsigned char,一個是unsigned char*.

更多資料在google中搜索“函數(shù)指針”.
0
回復(fù)
xing1234
LV.6
7
2008-01-14 11:23
@whatcall
參考:http://www.pconline.com.cn/pcedu/empolder/gj/c/0503/566020.html(*p)和tong_gao最后一個傳遞參數(shù)類型不一致,一個是unsignedchar,一個是unsignedchar*.更多資料在google中搜索“函數(shù)指針”.
謝謝!!加了*號后還是報的相同的錯誤.我再看看!
0
回復(fù)
xing1234
LV.6
8
2008-01-14 11:27
改了后的程序
#include
#include
#include
#include
unsigned char  tongdata[12];
write_at2401(unsigned char a,unsigned char b,unsigned char c)
{
a=0;
b=0;
c=0;
}
void tong_gao(unsigned char chao,unsigned char max,unsigned char da,unsigned char *b)//
{
  unsigned char id;
  id=*(b+da);
if(chao>max)   
chao=0;  
write_at2401(0xA0,da,id);
chao=1;
}
/*****************主程序區(qū)****************************/
main()
{
  unsigned char      chao,chu,max,*se_data;
void (*p)(unsigned char ,unsigned char ,unsigned char ,unsigned char *);//定義函數(shù)指針p
// void tong_gao(unsigned char ,unsigned char ,unsigned char ,unsigned char *);
chao=5;
chu=10;
max=12;
  p=tong_gao;        //p指向函數(shù)tong_gao
  se_data=tongdata;  //指針變量se_data指向數(shù)組tongdata[12]
  (*p)(chu,max,chao,se_data);//!!!!!!問題就在這里
}
0
回復(fù)
xing1234
LV.6
9
2008-01-14 11:38
@xing1234
改了后的程序#include#include#include#includeunsignedchar  tongdata[12];write_at2401(unsignedchara,unsignedcharb,unsignedcharc){a=0;b=0;c=0;}voidtong_gao(unsignedcharchao,unsignedcharmax,unsignedcharda,unsignedchar*b)//{  unsignedcharid;  id=*(b+da);if(chao>max)  chao=0;  write_at2401(0xA0,da,id);chao=1;}/*****************主程序區(qū)****************************/main(){  unsignedchar      chao,chu,max,*se_data;void(*p)(unsignedchar,unsignedchar,unsignedchar,unsignedchar*);//定義函數(shù)指針p//voidtong_gao(unsignedchar,unsignedchar,unsignedchar,unsignedchar*);chao=5;chu=10;max=12;  p=tong_gao;        //p指向函數(shù)tong_gao  se_data=tongdata;  //指針變量se_data指向數(shù)組tongdata[12]  (*p)(chu,max,chao,se_data);//!!!!!!問題就在這里}
se_data 是數(shù)組tongdata[12]的指針,問題就在這里.取消這個數(shù)組指針,改成(*p)(chu,max,chao);//!!!!!!!!!!!!!!!!!!!!!!!!!

void tong_gao(unsigned char chao,unsigned char max,unsigned char da,unsigned char *b)//去掉指針變量*b,就行了,但使用中這不是目的.
0
回復(fù)
whatcall
LV.5
10
2008-01-14 12:55
@xing1234
se_data是數(shù)組tongdata[12]的指針,問題就在這里.取消這個數(shù)組指針,改成(*p)(chu,max,chao);//!!!!!!!!!!!!!!!!!!!!!!!!!voidtong_gao(unsignedcharchao,unsignedcharmax,unsignedcharda,unsignedchar*b)//去掉指針變量*b,就行了,但使用中這不是目的.
我查了一下錯誤提示的解釋,應(yīng)該是C51編譯器不支持帶參數(shù)的函數(shù)指針調(diào)用,除非所有的參數(shù)可以用寄存器進行傳遞,而指向數(shù)組的指針實際上是數(shù)組的地址是16位,不可以用寄存器傳遞.看來你要想一下其他辦法了.

Error C212
Indirect Call: Parameters Do Not Fit Within Registers
Summary   *** Error C212
    Indirect Call: Parameters Do Not Fit Within Registers


Description   An indirect function call through a pointer cannot contain actual parameters. An exception to this rule is when all parameters can be passed in registers. This is due to the method of parameter passing employed by Cx51. The name of the called function
0
回復(fù)
xing1234
LV.6
11
2008-01-14 14:24
@whatcall
我查了一下錯誤提示的解釋,應(yīng)該是C51編譯器不支持帶參數(shù)的函數(shù)指針調(diào)用,除非所有的參數(shù)可以用寄存器進行傳遞,而指向數(shù)組的指針實際上是數(shù)組的地址是16位,不可以用寄存器傳遞.看來你要想一下其他辦法了.ErrorC212IndirectCall:ParametersDoNotFitWithinRegistersSummary  ***ErrorC212    IndirectCall:ParametersDoNotFitWithinRegistersDescription  Anindirectfunctioncallthroughapointercannotcontainactualparameters.Anexceptiontothisruleiswhenallparameterscanbepassedinregisters.ThisisduetothemethodofparameterpassingemployedbyCx51.Thenameofthecalledfunction
謝謝!!!!!
我也有這個想法,我在網(wǎng)上和書上查找了一些相關(guān)資料,都沒有用函數(shù)指針傳過數(shù)組指針變量,沒人用過.應(yīng)該是編釋器不支持.
0
回復(fù)
發(fā)