-2

I have got a source code in which there is a function that calculates week checksum. I need to pass a char array, let say, 'hello world'. How can I do that?? I tried some ways, e.g.:

char textArr[] = 'hello world'

but I get 'undefined reference' error.

unsigned int rs_calc_weak_sum(void const *p, int len) {
  unsigned char const    *buf = (unsigned char const *) p;
}

Please help me on this.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Satthy
  • 109
  • 1
  • 3
  • 10
  • [Asked literally 7 mins ago!?](http://stackoverflow.com/questions/18086992/undefined-reference-to-main-in-c) You guys are not aware of the search function, are you. –  Aug 06 '13 at 17:57
  • 1
    @H2CO3 in his defense, he asked this before the linked question existed. It doesn't change the fact this has been asked 300 times, and is clearly answered via a google search. – Scotty Bauer Aug 06 '13 at 17:59
  • 1
    @ScottyBauer [related](http://meta.stackexchange.com/questions/192123/should-stackoverflow-be-a-last-resort-resource) –  Aug 06 '13 at 18:00
  • 1
    @H2CO3 I agree, but with these people, they don't care. They're always going to come here first, even after we tell them about google. I'm on your side. – Scotty Bauer Aug 06 '13 at 18:02
  • Thank you guys for your time. but I got to tell you something. If I could understand those reference you provided above, I wouldn't have asked this question. never mind – Satthy Aug 06 '13 at 18:09

2 Answers2

0

Like this:

int main(){
  char textArr[] = "hello world";
  unsigned int checksum;
  checksum = rs_calc_weak_sum((const void*)textArr, sizeof(textArr));

}
Scotty Bauer
  • 1,277
  • 9
  • 14
  • Thnaks. Still I'm getting that error: undefined reference to `rs_calc_weak_sum(void const*, int)'. – Satthy Aug 06 '13 at 17:47
  • 1
    @Satthy your error isn't in the passing. Make sure either have the function that calls `rs_calc_weak_sum(void const*, int)` below the code for `rs_calc_weak_sum` or at the top of your .c file you put `unsigned int rs_calc_weak_sum(void const *p, int len);` – Scotty Bauer Aug 06 '13 at 17:50
  • No I have that function defined. and Crl+click goes to that function. – Satthy Aug 06 '13 at 17:52
  • @Satthy you clearly don't have it defined properly. – Scotty Bauer Aug 06 '13 at 17:53
  • @Satthy Then something else is going on (and we can't guess what it is from the little information given). Where is your rs_calc_weak_sum defined relative to where the error is ? Are you mixing C and C++ code ? What kind of program are you Ctrl+click'ing in to jump to that function, and possibly also use to build your program ? Perhaps you for some reason arn't compiling and linking in the file where rs_calc_weak_sum is defined. – nos Aug 06 '13 at 19:18
  • @nos thanks your help. after I read your replay. I went through some c and c++ codes and find out that I should have include my header file like #include "checksum.h". earlier it was like #include I didn't know the difference. – Satthy Aug 06 '13 at 19:47
0

make sure your function rs_calc_weak_sum is prototyped/defined before main.

Hrishi
  • 7,110
  • 5
  • 27
  • 26
  • Yes I have that function defined in another file. and Crl+click goes to that function. :D – Satthy Aug 06 '13 at 17:54
  • @Satthy, did you include the correct .h file, and when you compile did you include the .c file that holds the function? – Scotty Bauer Aug 06 '13 at 17:55