Solved
"local variable".. "used without having been initialized"?
Posted on 2003-11-13
I am getting an error ...node0.c(33) : warning C4700: local variable 'node0' used without having been initialized
but I thought I did initialize it? Part of my code is shown below...
____________________________________________________________________________________________
#include "prog3.h"
#include <stdio.h>
extern struct rtpkt {
int sourceid; /* id of sending router sending this pkt */
int destid; /* id of router to which pkt being sent
(must be an immediate neighbor) */
int mincost[4]; /* min cost to node 0 ... 3 */
};
extern int TRACE;
extern int YES;
extern int NO;
struct distance_table
{
int costs[4][4];
} dt0;
printdt0(distance_table);
/* students to write the following two routines, and maybe some others */
/************************************************************************************************************************************/
/* rtinit0() -- This routine will be called once at the beginning of the emulation. rtinit0() has no arguments. */
void rtinit0()
{
struct rtpkt *pkt2send;
struct distance_table *node0;
int i, j;
/* default the distance table by setting the cost to infinity (999)). */
for (i=0; i<=3; i++){
for (j=0; j<=3; ++j)
node0->costs[i][j] = 999;
}
/* Initialize the distance table reflect the direct costs */
node0->costs[0][0] = 0;
node0->costs[1][1] = 1;
node0->costs[2][2] = 3;
node0->costs[3][3] = 7;
/* Finding the mincost from the distance table */
for (i=0; i<=3; i++){
pkt2send->mincost[i] = 999; // default mincost
}
for (i=0; i<=3; i++){
for (j=0; j<=3; ++j){
if (node0->costs[i][j]<pkt2send->mincost[i]){
pkt2send->mincost[i] = node0->costs[i][j];
}
}
}
/* Then send its distance vector directly connected neighbors the cost of it minimum cost paths to all other network nodes. */
pkt2send->sourceid = 0;
pkt2send->destid = 1;
tolayer2(pkt2send);
pkt2send->destid = 2;
tolayer2(pkt2send);
pkt2send->destid = 3;
tolayer2(pkt2send);
printdt0(node0);
}
/************************************************************************************************************************************/
/* rtupdate0(struct rtpkt *rcvdpkt) -- This routine will be called when node 0 receives a routing packet (distance vector) from its
directly connected neighbors. */
void rtupdate0(rcvdpkt)
struct rtpkt *rcvdpkt;
{
int k, i, source;
struct rtpkt *pkt2send;
struct distance_table *node0;
/* the received distance vectors are used to update its own distance table (as specified by the distance vector algorithm). */
source = rcvdpkt->sourceid;
for (i=0; i<=3; i++){
node0->costs[i][source] = node0->costs[i][source] + rcvdpkt->mincost[i];
}
/* Finding it's minimum cost paths to all other neighboring nodes
(the distance vector). */
k = 0; //check to see if the distance vector gets updated
for (i=0; i<=3; i++){
if (pkt2send->mincost[0]<node0->costs[0][i]) {
pkt2send->mincost[0]=node0->costs[0][i];
k = 1;
}
if (pkt2send->mincost[1]<node0->costs[1][i]) {
pkt2send->mincost[1]=node0->costs[1][i];
k = 1;
}
if (pkt2send->mincost[2]<node0->costs[2][i]) {
pkt2send->mincost[2]=node0->costs[2][i];
k = 1;
}
if (pkt2send->mincost[3]<node0->costs[3][i]) {
pkt2send->mincost[3]=node0->costs[3][i];
k = 1;
}
}
/* If the distance vector is updated, then
This distance vector is sent to neighboring nodes in a routing packet by calling the routine tolayer2()*/
if ( k = 1) {
pkt2send->sourceid = 0;
pkt2send->destid = 1;
tolayer2(pkt2send);
pkt2send->destid = 2;
tolayer2(pkt2send);
pkt2send->destid = 3;
tolayer2(pkt2send);
}
printdt0(node0);
}
/************************************************************************************************************************************/
/* This routine will print the distance table for node 0 in a pretty way. It is passed a pointer to a structure of type distance_table.
printdt0() and the structure declaration for the node 0 distance table are declared in the file node0.c. Similar pretty-print
routines are defined for you in the files node1.c, node2.c node3.c. */
printdt0(dtptr)
struct distance_table *dtptr;
{
printf(" via \n");
printf(" D0 | 1 2 3 \n");
printf(" ----|-----------------\n");
printf(" 1| %3d %3d %3d\n",dtptr->costs[1][1],
dtptr->costs[1][2],dtptr->costs[1][3]);
printf("dest 2| %3d %3d %3d\n",dtptr->costs[2][1],
dtptr->costs[2][2],dtptr->costs[2][3]);
printf(" 3| %3d %3d %3d\n",dtptr->costs[3][1],
dtptr->costs[3][2],dtptr->costs[3][3]);
}