0

This project 1 can compile on Windows and macOS (with a few minor tweaks). On Ubuntu it fails to compile, with a lot of errors like:

ldrawloader/src/ldrawloader.cpp:3214:19: note: candidate template ignored: deduced type 'LdrVector *' of 2nd parameter does not match adjusted type 'LdrVector *__restrict' of argument [with T = LdrVector, Tout = LdrVector] static uint32_t u32_append(LdrRawData& raw, Tout*& ptrRef, const Loader::TVector& vec, size_t divisor = 1)

I tried to switch to clang on Ubuntu (apt install clang, then export CC=clang, export CXX=clang++, clean rebuild) but it still fails to compile (but I'm 100% sure I'm using clang and not gcc, as I see the compiler command invocation which starts with /usr/bin/clang++ and the compiler error is slightly different; in fact the error you see above is from clang-14 on Ubuntu).

According to 2, __restrict can be removed and code should work in the same way. So I replaced #define LDR_RESTRICT __restrict with #define LDR_RESTRICT in src/ldrawloader.h:107 and now I can compile it successfully.

Question time:

  1. Why __restrict has been used there?
  2. I have the same clang version (14.0.0) on Ubuntu and on macOS: why on macOS I've been able to compile it without modifications?
fferri
  • 18,285
  • 5
  • 46
  • 95
  • TL;DR: `restrict` is not standard C++. It is a common extension that means "the memory this points to will not overlap with any of the other arguments". This is meant to enable optimizations. You can remove it and the code should have the same behavior. – Aykhan Hagverdili Mar 30 '23 at 14:40

0 Answers0