ATen icon indicating copy to clipboard operation
ATen copied to clipboard

PRId64 (__STDC_FORMAT_MACROS) in older g++ again

Open ShigekiKarita opened this issue 6 years ago • 1 comments

related to this issue https://github.com/pytorch/pytorch/issues/3571 Since header organization is changed, this happens again in my CentOS7 & GCC4.8.5.

The problem is that __STDC_FORMAT_MACROS is defined after #include <inttypes.h>.

  • As a github search indicates that inttypes.h is included in THGeneral.h.
  • Then THXxx.h were included at https://github.com/zdevito/ATen/blob/master/src/ATen/templates/TensorDerived.h#L3
  • That header is included before #define __STDC_FORMAT_MACROS at https://github.com/zdevito/ATen/blob/master/src/ATen/templates/TensorDerived.cpp#L9

I confirmed and suggest two solutions for this problem.

  1. global change: add_definitions(-D__STDC_FORMAT_MACROS) in CMakeLists.txt
  2. local change: #define __STDC_FORMAT_MACROS before $th_headers at https://github.com/zdevito/ATen/blob/master/src/ATen/templates/TensorDerived.h#L3 (also suggested in https://github.com/pytorch/pytorch/issues/3949#issuecomment-348368810)

I prefer 1st one because it covers every header files while you use CMake.

ShigekiKarita avatar Dec 06 '17 02:12 ShigekiKarita

Thank you! That helps a lot! It would be better if anyone could merge this change.

chaihua483 avatar Dec 11 '17 04:12 chaihua483