Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Pl.Help...
I use c very very infrequently...
I have a funny problem,the Compiler gives warning at lines (1),(2),(3),(4)
The executable works as required.
what changes should I make to shoo away the warnings.
Microsoft's c++ is even more nastier for, ** variables.
I use them when i want to return values
via parameters.

C#
static void FilterAContour(gpc_vertex * Poly,int ** pnumVertices )
{  int          c, v, CnumVertices,FnumVertices;
   BOOL  ChangeDone;
 (1)  CnumVertices=*pnumVertices;
  

   if(CnumVertices <=1){
 (2)  *pnumVertices=1;
    return;
   }     
      
    if(CnumVertices==2)
    { if((Poly[0].x==Poly[1].x) && (Poly[0].y==Poly[1].y) )
    (3)    *pnumVertices=1;
      else
   (4)    *pnumVertices=2;
       return;
     }
Posted
Updated 24-May-12 1:02am
v2
Comments
Jim Jos 24-May-12 7:07am    
What is the warning message?

I'm not in the least surprised!
Cutting out the "dead wood":
C++
static void func(int ** ppi )
{  int i;
   i = *ppi;
   *ppi = 1;
}
ppi is a "pointer-to-a-pointer-to-an-int" and the body of your function is using it as a "pointer-to-an-int"

So the compiler correctly complains.
What if the calling function uses the value it hands you as a genuine pointer-to-a-pointer-to-an-int? It tries to use an integer value "1" as a pointer...


What can you do to fix it? Use it as the type it is declared as, or change the declaration to match the usage!
 
Share this answer
 
Comments
Mohibur Rashid 24-May-12 23:08pm    
Good point
In addition to what Griff said about fixing your declaration so you're passing a pointer to int rather than a pointer to pointer to int I've got a question back for you...

Your function doesn't return anything. Yet you're using an out parameter (some what incorrectly)... Why not return the number of vertices and then you'll have one less thing to mess around with and get wrong? Then your code could become something like...
C++
static int FilterAContour(gpc_vertex * Poly, int numVertices )
{
  if(numVertices <=1)
   {
       return 1;
   }
   else if(numVertices==2)
   {
       return ((Poly[0].x==Poly[1].x) && (Poly[0].y==Poly[1].y) ) ? 1 : 2;
   }
   else
   {
       return -1;
   }
}
Now I know there's probably more to the code that what you've presented here but just in that little chunk it's cleared up stuff no end. Stick in a poly equality function (equal rights for parrots? Outrageous!) and it becomes even simpler:
C++
static int EqualXandY( const gpc_vertex *p1, const gpc_vertex *p2 )
{
    return (p1.x==p2.x) && (p1.y==p2.y);
}

static int FilterAContour(gpc_vertex * Poly, int numVertices )
{
  if(numVertices <=1)
   {
       return 1;
   }
   else if(numVertices==2)
   {
       return ( EqualXandY( &Poly[ 0 ], &Poly[ 1 ] ) ? 1 : 2;
   }
   else
   {
       return -1;
   }
}
I'm not sure if this is exactly correct (I haven't compiled it) but to my self taught eye it looks a lot easier to read!

Edit: Added in the final else to stop some compilers (correctly) whinging about some control paths not returning a value.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900