0
ライブラリに存在する関数を呼び出すプログラムがあります。関数の引数は関数ポインタです。関数ポインタをパラメータとして渡しているときにエラーが発生しました。
#include<stdio.h>
#include<stdlib.h>
int send_data(int (*func_pointer)(&data_buffer)) //error
{
func_pointer=spi_write(); // assigning the function pointer to SPI WRITE function
return;
}
libexample.c
Helloworld.c
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "helloworld.h"
struct data_buffer
{
char name[10];
}data;
int main()
{
int result;
int (*func_pointer)(&data_buffer); //function pointer which takes structure as parameter
result=send_data(func_ponter); //error
func_pointer(&data_buffer); //call the SPI write
}
helloworld.h
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
/* Some cross-platform definitions generated by autotools */
#if HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
/*
* Example function
*/
struct data_buffer;
extern int send_data(int (*func_pointer)(&data_buffer)); //is the declaration correct
#endif
ので、プロジェクトの私の目的は、パラメータとして関数ポインタを送信することですsend_data関数。ライブラリプログラムでは、関数ポインタをspi_write()関数に割り当ててから、Helloworldプログラムの関数ポインタを使用してSPI_Writeを呼び出すことができます。
パラメータに 'spi_write'を割り当てると、何が達成されますか? *は* 'spi_write'ですか? (また、 'x = y;'と書くと、あなたは「yをxに割り当てる」ということになります。 – molbdnilo