[petsc-dev] clang warning, 64bit indices

Satish Balay balay at mcs.anl.gov
Wed Mar 9 13:51:10 CST 2016


On Wed, 9 Mar 2016, Lisandro Dalcin wrote:

> I got the following warning using clang on Mac with 64bit indices. The
> warning is legit, however fixing it as suggested might be problematic
> on Window, I think we should use "%I64d" in that platform (see
> http://stackoverflow.com/questions/18107426/printf-format-for-unsigned-int64-on-windows)
> 
> Satish, any change you could confirm?
> 
> 
> /Users/dalcinl/Devel/petsc-dev/src/sys/classes/viewer/impls/ascii/filev.c:1054:63:
> warning: format specifies type 'long *' but the argument has type
> 'PetscInt *' (aka 'long long *')
>       [-Wformat]
>     else if (dtype == PETSC_INT)     ret = fscanf(fd, "%ld",
> &(((PetscInt*)data)[i]));
>                                                        ~~~
> ^~~~~~~~~~~~~~~~~~~~~~~
>                                                        %lld
> 
> 

Well the following works..

-----------------------------
sbalay at ps3 ~/junk
$ cat te.c
#include <stdio.h>
#include <stdlib.h>
int main()

{
  __int64 a;
  char c[10] = "349";

  sscanf(c,"%I64d",&a);
  printf("%I64d",a);
  return 0;
}

sbalay at ps3 ~/junk
$ cl te.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

te.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:te.exe 
te.obj 

sbalay at ps3 ~/junk
$ ./te.exe
349
sbalay at ps3 ~/junk
$ 

-------------------

PetscViewerASCIIRead() should have same #ifdef structure as petscsys.h for the 64bit type...

#if defined(PETSC_HAVE_STDINT_H)
  scanf(format for  int64_t);
#elif (PETSC_SIZEOF_LONG_LONG == 8)
  scanf(format for long long);
#elif defined(PETSC_HAVE___INT64)
   scanf(format for __int64 - aka windows);
#endif


Satish



More information about the petsc-dev mailing list