how to eliminate this warning?

Discussion in 'C++' started by blackswift, Feb 24, 2006.

  1. blackswift

    blackswift Guest

    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;
    }
    blackswift, Feb 24, 2006
    #1
    1. Advertising

  2. * 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]


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Feb 24, 2006
    #2
    1. Advertising

  3. blackswift

    blackswift Guest

    thanks. i got it.

    i thought this warning is caused by the arugments tansforming.
    but it is caused by the assignment.
    blackswift, Feb 24, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pete Becker
    Replies:
    0
    Views:
    1,365
    Pete Becker
    Feb 10, 2005
  2. B. Williams

    warning C4267 and warning C4996

    B. Williams, Oct 26, 2006, in forum: C++
    Replies:
    17
    Views:
    2,613
  3. WARNING! Prosoftstore.com is a SCAM! WARNING!

    , Jul 8, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    305
  4. Julian Mehnle
    Replies:
    17
    Views:
    843
    Julian Mehnle
    May 18, 2006
  5. Replies:
    11
    Views:
    4,122
    sameer k
    Sep 6, 2012
Loading...

Share This Page