News for hackers. Stuff that matters.

evozer

There is, it's called static. Just hide it in a .cpp file and expose the real function in a header file.
I don't understand your example, why would

(1 + 2.060) - 2.060 == 0

while

1 + (2.060 - 2.060) == 1?

Am I just misunderstanding what you wrote?

Re:Let's remove quaternions from every 3D engine (2018) on Friday January 31, 2020 @10:44AM (#22202552)
shouldn't it be e^tau*i = 1 if tau is 2pi?
Re:Use mmap with care on Thursday May 02, 2019 @06:15AM (#19806331)
Did you consider emulating mmap yourselves?

  "Memory mapped files work by mapping the full file into a virtual address space and then using page faults to determine which chunks to load into physical memory. In essence it allows you to access the file as if you had read the whole thing into memory, without actually doing so."
I feel like this could be done in c++ directly, by maintaining an internal cache for each file that keeps track of which parts of the file are loaded and uses read() to load chunks on demand. Error handling would be a lot simpler (no signals, just a failed read()) and there would be less OS-specific code.
I had to go to the last page and click "repeat the search with the omitted results included" to make it show up at all. After doing that it was the third result.
Re:Oboe: A C++ library for low latency audio in Android on Friday October 12, 2018 @10:10AM (#18201512)
I looked at the implementation of the openStream() function:

  AudioStream *AudioStreamBuilder::build() {
      AudioStream *stream = nullptr;
      if (mAudioApi == AudioApi::AAudio && isAAudioSupported()) {
          stream = new AudioStreamAAudio(*this);  

      // If unspecified, only use AAudio if recommended.
      } else if (mAudioApi == AudioApi::Unspecified && isAAudioRecommended()) {
          stream = new AudioStreamAAudio(*this);
      } else {
          if (getDirection() == oboe::Direction::Output) {
              stream = new AudioOutputStreamOpenSLES(*this);
          } else if (getDirection() == oboe::Direction::Input) {
              stream = new AudioInputStreamOpenSLES(*this);
          }
      }
      return stream;
  }  

  Result AudioStreamBuilder::openStream(AudioStream **streamPP) {
      if (streamPP == nullptr) {
          return Result::ErrorNull;
      }
      *streamPP = nullptr;
      AudioStream *streamP = build();
      if (streamP == nullptr) {
          return Result::ErrorNull;
      }
      Result result = streamP->open(); // TODO review API
      if (result == Result::OK) {
          *streamPP = streamP;
      }
      return result;
  }
Doesn't this leak memory if streamP->open() fails? I'm also surprised they are using new instead of unique_ptr, especially since one of their listed benefits is "Convenient C++ API (uses the C++11 standard) ".
OP said $5 for 84 days though, not a month.
Re:OpenAI Five: Goals and Progress on Tuesday August 21, 2018 @07:08AM (#17808577)
But it would be fun to see NP bodyblock the entire enemy team with one set of treants.
Re:How to Write Unmaintainable Code (2017) on Friday August 17, 2018 @09:57AM (#17782841)
If you want to be more efficient, you can also use a union for this.

typedef union { int i; float f; double d; long l; char c; void *p; ... } var;

Now you might also get some nice float-interpreted-as-int bugs if you forget the type!

You can also kind of pretend that you have C#-style type inference:

var x = { .i = 10 }; var y = { .f = 2.0f };