[petsc-dev] need C++ expert help

Satish Balay balay at mcs.anl.gov
Tue Sep 13 14:50:14 CDT 2016


This works..

Satish

---------

diff --git a/src/mat/examples/tests/ex45.c b/src/mat/examples/tests/ex45.c
index 63d0a30..37f68e3 100644
--- a/src/mat/examples/tests/ex45.c
+++ b/src/mat/examples/tests/ex45.c
@@ -72,7 +72,7 @@ void Store2DArray(int m,int n,double *a,const char *filename,int *fdd)
       vals[i+m*j] = a[j+i*n];
     }
   }
-  if (write(fd,vals,m*n*sizeof(double)) != ((unsigned int) (m*n))*sizeof(double)) abort();
+  if ((size_t)write(fd,vals,m*n*sizeof(double)) != (size_t)(m*n*sizeof(double))) abort();
   free(vals);
 
 }
@@ -94,7 +94,7 @@ void Store1DArray(int m,double *a,const char *filename,int *fdd)
   }
   if (write(fd,&classid,sizeof(int)) != sizeof(int)) abort();
   if (write(fd,&m,sizeof(int)) != sizeof(int)) abort();
-  if (write(fd,a,m*sizeof(double)) != ((unsigned int)m)*sizeof(double)) abort();
+  if ((size_t)write(fd,a,m*sizeof(double)) != (size_t)(m*sizeof(double))) abort();
 }
 

On Tue, 13 Sep 2016, Satish Balay wrote:

> I would tink if its typecast to same type - comparision would work..
> 
> if ((ssize_t)write(fd,vals,m*n*sizeof(double)) != (ssize_t)(m*n*sizeof(double))) abort();
> 
> I'll give this a try...
> 
> Satish
> 
> On Tue, 13 Sep 2016, Barry Smith wrote:
> 
> > 
> >    I need help from someone who knows the subtleties of c++.  We have a PETSc example that always compiles fine with C but generates annoying warnings with C++. I've tried many different variants to eliminate the warnings with no luck
> > 
> >    Any help is appreciated.
> > 
> >     Barry
> > 
> > 
> > mpicxx -o ex45.o -c -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fvisibility=hidden -g -O   -fPIC    -I/sandbox/petsc/petsc.clone-3/include -I/sandbox/petsc/petsc.clone-3/arch-linux-opt-cxx-quad/include -I/usr/include/mpich2    `pwd`/ex45.c
> > /sandbox/petsc/petsc.clone-3/src/mat/examples/tests/ex45.c: In function ‘void Store2DArray(int, int, double*, const char*, int*)’:
> > /sandbox/petsc/petsc.clone-3/src/mat/examples/tests/ex45.c:75:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
> >    if (write(fd,vals,m*n*sizeof(double)) != ((unsigned int) (m*n))*sizeof(double)) abort();
> >                                          ^
> > /sandbox/petsc/petsc.clone-3/src/mat/examples/tests/ex45.c: In function ‘void Store1DArray(int, double*, const char*, int*)’:
> > /sandbox/petsc/petsc.clone-3/src/mat/examples/tests/ex45.c:97:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
> >    if (write(fd,a,m*sizeof(double)) != ((unsigned int)m)*sizeof(double)) abort();
> > 
> > 
> > It can be found here ftp://ftp.mcs.anl.gov/pub/petsc/nightlylogs/archive/2016/09/13/examples_next_arch-linux-opt-cxx-quad_grind.log
> 


More information about the petsc-dev mailing list