how to eliminate this warning?

B

blackswift

hello ,all

i got this warning:

under emacs using GCC 4.0.1 gpp(DJGPP) compiler:

gpp -Wall -g lizards.cpp
Invalid keyboard code specified
lizards.cpp: In function 'int maxflow(int (*)[1000], int, int, int)':
lizards.cpp:56: warning: suggest parentheses around assignment used as
truth value

part of my code:
typedef int Graph[MAXN][MAXN];
Graph g;
.....
int augment(Graph g, int n, int s, int t);
....
int maxflow(Graph g, int n, int s, int t)


complete listing:

#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
#define REP(i,n) for(int _n=(n),i=0;i<_n;i++)
#define FOR(i,a,b) for(int _b=(b),i=(a);i<=_b;i++)
/////////
const int INF = 1000000000;
const int MAXN = 1000;
typedef int Graph[MAXN][MAXN];
Graph g;
int cap[MAXN],vis[MAXN],src[MAXN];
int n,m,disLeap,nlizards,nvec,source,sink;
char map[30][30], lid[30][30];

int augment(Graph g, int n, int s, int t)
{
int i, j;
int max, mloc;

memset(vis,0,sizeof(vis));
memset(cap,0,sizeof(cap));
cap = INF;
while (1) {
mloc = -1;
max = 0;
for (i=0; i<n; i++)
if (!vis && cap>max) {
mloc = i;
max = cap;
}
if (mloc == -1) return 0;
if (mloc == t) break;

vis[mloc] = 1;
for (i=0; i<n; i++)
if (g[mloc]>cap && max>cap) {
cap = g[mloc];
if (cap>max) cap = max;
src = mloc;
}
}
max = cap[t];
for (i=t; i!=s; i=src) {
j = src;
g[j] -= max;
g[j] += max;
}
//cerr << max << endl;
return max;
}

int maxflow(Graph g, int n, int s, int t)
{
int c=0,p;
while (p=augment(g, n, s, t)) c+=p;
return c;
}

inline int dist2(int x1,int y1,int x2,int y2) {
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
inline int inNode(int r, int c) {
return (r*m+c)*2+2;
}
inline int outNode(int r, int c) {
return (r*m+c)*2+3;
}

void read_graph()
{
memset(g,0,sizeof(g));
nlizards = 0;
source = 0; sink = 1;

scanf("%d%d\n", &n,&disLeap);
REP(i,n) gets(map);
REP(i,n) gets(lid);
m = strlen(map[0]);
nvec = n*m*2+2;

int leap2 = disLeap*disLeap;
REP(row,n) REP(col,m) {
int in = inNode(row,col);
int out = outNode(row,col);
g[in][out] = map[row][col]-'0';
if (lid[row][col]=='L') {
g[source][in] = 1;
++nlizards;
}

if ((row<disLeap || row>n-1-disLeap ||
col<disLeap || col>m-1-disLeap))
g[out][sink] = INF;

REP(i,n) REP(j,m)
if (((row!=i || col!=j)
&& dist2(row,col,i,j)<=leap2))
g[out][inNode(i,j)] = INF;
}
}

int main()
{
int nkase;
freopen("lizards.in","r",stdin);
scanf("%d",&nkase);
FOR(kase,1,nkase) {
read_graph();
//cout << nvec << " " << source << " " << sink << endl;
int res = nlizards - maxflow(g, nvec, source, sink);
printf("Case #%d: ", kase);
if (res==0) printf("no lizard was left behind.\n");
else if (res==1) printf("1 lizard was left behind.\n");
else printf("%d lizards were left behind.\n", res);
}
return 0;
}
 
A

Alf P. Steinbach

* blackswift:
hello ,all

i got this warning:

under emacs using GCC 4.0.1 gpp(DJGPP) compiler:

gpp -Wall -g lizards.cpp
Invalid keyboard code specified
lizards.cpp: In function 'int maxflow(int (*)[1000], int, int, int)':
lizards.cpp:56: warning: suggest parentheses around assignment used as
truth value

As the warning says, int function 'maxflow' (which is just a few lines)
you have used an assignment as a truth value. The warning also says how
to eliminate the warning if that is really what you mean. Have you at
all _read_ the warning?

[extranous code listing snipped]
 
B

blackswift

thanks. i got it.

i thought this warning is caused by the arugments tansforming.
but it is caused by the assignment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top