atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
227 stars 31 forks source link

ENH: add dpp build-in support for int64_t? #340

Closed mw66 closed 1 year ago

mw66 commented 1 year ago

These types are defined in:

#include <stdint.h>

and can be mapped to D types.

right now, int64_t only mapped to int64_t, which is not a correct D type.

atilaneves commented 1 year ago

Please post the code that exhibits the bug.

mw66 commented 1 year ago
$ cat cpp.dpp 
#include <stdint.h>

class PriceBarI {
 public:
  // OHLC chart
  virtual double open_()   = 0;
  virtual double high_()   = 0;
  virtual double low_()    = 0;
  virtual double close_()  = 0;
  virtual double volume_() = 0;
  virtual int64_t  millis_() = 0;
};

$ ~/.dub/packages/dpp/0.5.4/dpp/bin/d++ --keep-d-files --preprocess-only --parse-as-cpp ./cpp.dpp

$ tail cpp.d
class PriceBarI {
 public:
  // OHLC chart
  virtual double open_() = 0;
  virtual double high_() = 0;
  virtual double low_() = 0;
  virtual double close_() = 0;
  virtual double volume_() = 0;
  virtual int64_t millis_() = 0;
};

The int64_t in the output didn't change.

I think we should handle these types in :

/usr/include/bits/stdint-intn.h

typedef __int8_t int8_t;
typedef __int16_t int16_t;
typedef __int32_t int32_t;
typedef __int64_t int64_t;

/usr/include/bits/stdint-uintn.h

typedef __uint8_t uint8_t;
typedef __uint16_t uint16_t;
typedef __uint32_t uint32_t;
typedef __uint64_t uint64_t;

since they have easy mapping to D.

atilaneves commented 1 year ago

Why did you expect int64_t to change? dpp outputs an alias for it, because there's a typedef in stdint.h. This is the expected behaviour. It would be a bug if it didn't compile, or if int64_t meant anything other than a signed 64 bit integer.

Also, .dpp files are supposed to be D files except for the #include directives and use of macros from the headers it includes, you have C++ syntax in there.