Methods 将(无效常量*x)强制转换为(无符号字符常量*y)

Methods 将(无效常量*x)强制转换为(无符号字符常量*y),methods,types,parameter-passing,Methods,Types,Parameter Passing,我正在分析一段源代码,其中定义了一个方法: unsigned int rs_calc_weak_sum(void const *p, int len) { unsigned char const *buf = (unsigned char const *) p; } 应该将什么类型的参数传递到此方法 请帮帮我 谢谢 任何指针都可以传递给void*参数。传递什么“应该”,取决于代码对该参数所做的操作 char array[12] = "Hello World"; unsigned in r

我正在分析一段源代码,其中定义了一个方法:

unsigned int rs_calc_weak_sum(void const *p, int len) {
unsigned char const    *buf = (unsigned char const *) p;
}
应该将什么类型的参数传递到此方法

请帮帮我


谢谢

任何指针都可以传递给void*参数。传递什么“应该”,取决于代码对该参数所做的操作

char array[12] = "Hello World";
unsigned in res = 0;
res = rs_calc_weak_sum(array, 12);

#include <stdio.h>
int main ( void )
{
  char filename[] = "file.txt";
  FILE *file = fopen ( filename, "r" );

  if (file != NULL) {
    char line [1000];
    while(fgets(line,sizeof line,file)!= NULL) /* read a line from a file */ {
      res = rs_calc_weak_sum(line, 1000);
    }

    fclose(file);
  }
  else {
    perror(filename); //print the error message on stderr.
  }

  return 0;
}
char数组[12]=“你好世界”;
在res中无符号=0;
res=rs\u计算弱和(数组,12);
#包括
内部主(空)
{
char filename[]=“file.txt”;
FILE*FILE=fopen(文件名,“r”);
如果(文件!=NULL){
字符行[1000];
while(fgets(line,sizeof line,file)!=NULL)/*从文件中读取一行*/{
res=rs\u calc\u弱和(第1000行);
}
fclose(文件);
}
否则{
perror(filename);//在stderr上打印错误消息。
}
返回0;
}

指向任何东西的指针。毕竟,这就是
void*
所表示的。应该是还是可以是?它看起来像是接受任何常量指针,并将其重新转换为无符号char常量指针。“这就是它应该做的吗?”吉姆,谢谢。对我需要传递一个字符数组。你能给我举个例子吗?@larsmans,谢谢。我明白了。我需要传递一个字符数组。请给我举个例子。@Satthy:这是哪种语言?C还是C++?我需要从GEC文件中获取一个字符块。然后我需要将该块传递到这个方法中。请给我一些示例代码。谢谢,谢谢。我已经试过这个了。但它给了我一个错误,说“未定义对rs_calc_弱_sum(void const*,int)”听起来像是链接器的问题。你在做什么?