user494461
user494461

Reputation:

Variable is used without being initiallized

I have

run(){
...
struct sockaddr_in from;
int i = recvpacket(buffer,from, fromlen)
...
}


recvpacket(char *buffer, struct sockaddr_in from, int fromlen)
{
//udp recvfrom stores the address of the sender in from
}

I get the following runtime Error in VC++

runtime check failure - the variable 'from' is used without being initialized

should I pass by reference, how should I do that?

Upvotes: 0

Views: 171

Answers (2)

Germann Arlington
Germann Arlington

Reputation: 3353

In your run() method: struct sockaddr_in from = {0}; and pass it by reference to be updated in called method

Upvotes: 1

pagra
pagra

Reputation: 665

Two things to fix:

  • to remove the warning you have to initialize from like this for example:

    struct sockaddr_in from= {0};

  • to get the address when calling recvpacket you have to declare it as by reference

    recvpacket(char *buffer, struct sockaddr_in& from, int fromlen)

Upvotes: 2

Related Questions