locked
Use of restrict keyword in stdlib.h RRS feed

  • Question

  • Hi,

    I'm trying to use the C99 restrict keyword in my program, as documented here:

    http://msdn.microsoft.com/en-us/library/5ft82fed(v=vs.80).aspx

    But I'm having issues getting it to do the correct thing in some specific cases (it mostly works OK):

    #define restrict __restrict

    #include <stdlib.h>

    int main(void) {

        printf("Hello world!\n");

    }

    This fails to compile:

    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdlib.h(598): error C2485: '__restrict' : unrecognized extended attribute

    (and then that repeats for line 600, 602, 604, 606, 607, 609, 611, 613 and 615.)

    Inverting the define and the include fixes it (and gives the expected behaviour if I were to actually use it in a meaningful way), but for larger existing codebases it seems like an unideal solution to have to redo the whole codebase to ensure that stdlib.h is included before config.h in every single source file. Is this a bug, or expected and documented behaviour?

    Wednesday, June 13, 2012 11:17 PM

Answers

  • On 6/13/2012 7:17 PM, rbultje wrote:

    #define restrict __restrict
    #include <stdlib.h>

    This fails to compile:

    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdlib.h(598): error C2485: '__restrict' : unrecognized extended attribute

    The header uses __declspec(restrict), and your #define messes it up.

    Is this a bug, or expected and documented behaviour?

    It is well-known behavior that #defining random identifiers may cause random problems in the code that just happens to use those identifiers. That's the nature of the preprocessor. You can't really expect a piece of documentation specifying every single identifier you shouldn't be redefining.


    Igor Tandetnik

    • Marked as answer by rbultje Thursday, June 14, 2012 3:49 PM
    Wednesday, June 13, 2012 11:44 PM