I am using Code::Blocks 10.05, and mingw. It seems the compiler does not recognized restrict qualifier and return “error: expected ‘;’, ‘,’ or ‘)’ before ‘src'”. Do I need to pass any compiler option in order to compile it correctly?
int inet_pton4 (const char *restrict src, unsigned char *restrict dst)
p/s: it seems mingw does not support inet_pton4, so i tried to integrate an open-source version into my code.
If your compiler does not support the
restrictkeyword, just take that keyword out (a).It’s used to indicate to the compiler that you (the developer) promise that the pointers follow certain properties involving aliasing, and this, in turn, allows the compiler to perform certain optimisations that would otherwise not necessarily be safe.
If you leave off that keyword in a compiler that supports it, it prevents those optimisations (slight downside).
If you leave it off for compilers that don’t support that keyword, the downside is nil (since they don’t support those optimisations anyway) and the upside is considerable, as in “it will compile for you” 🙂
(a) You may want to ensure you’re compiling in C99 mode first. While it may be true that you’re using an older
gccthat doesn’t understandrestrict, it’s equally possible that you’re not compiling in C99 mode, such as with-std=c99(gccdocs seem to indicate thatrestricthas been supported even back to version 3.0).If, for some reason you cannot activate C99 mode, I think
gcchas an extension that allows you to use__restrict.