Gcc Restrict Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn
Gcc Restrict Keyword
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags clang __restrict Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you,
__restrict__
helping each other. Join them; it only takes a minute: Sign up errors as i use the restrict qualifier up vote 5 down vote favorite 1 When I compile the following program I get errors : gcc tester.c cuda __restrict__ -o tester tester.c: In function ‘main’: tester.c:7:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptr_X’ tester.c:7:17: error: ‘ptr_X’ undeclared (first use in this function) tester.c:7:17: note: each undeclared identifier is reported only once for each function it appears in tester.c:10:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptr_Y’ tester.c:10:17: error: ‘ptr_Y’ undeclared (first use in this function) #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error using restrict keyword up http://stackoverflow.com/questions/13155059/errors-as-i-use-the-restrict-qualifier vote 5 down vote favorite 1 In the following example: void foo (double *ptr) { const double * restrict const restr_ptr=ptr; } I get this error: error: expected a ";" const double * restrict const restr_ptr=ptr; ^ I compile with -std=c99, using gcc 3.4 Any Ideas? c++ c optimization restrict-qualifier share|improve this question edited Aug 2 '12 at 18:10 Mat 135k21235274 asked Sep 8 '09 http://stackoverflow.com/questions/1395396/error-using-restrict-keyword at 17:59 vehomzzz 11.7k46128191 It compiles for me just fine. Have you got a recent version of GCC? –Cat Plus Plus Sep 8 '09 at 18:07 That code compiles for me on Sun C 5.8 and GCC 3.4.6. Comeau online only complains about the unused variable declaration. Please provide more details about your environment. –Rob Kennedy Sep 8 '09 at 18:10 ... but Comeau was in C99 mode. When I put it in C++ mode, it complains about the same thing. –Rob Kennedy Sep 8 '09 at 18:16 I am using gcc 3.4 –vehomzzz Sep 8 '09 at 18:16 I should have been more specific about what "the same thing" meant in my last comment. In C++ mode, Comeau says it expects a semicolon, just like Enigma's compiler. –Rob Kennedy Sep 8 '09 at 18:28 | show 2 more comments 1 Answer 1 active oldest votes up vote 9 down vote accepted In C++, restrict is not a keyword (except for Microsoft extensions). It doesn't mean what it does in C. It looks as though you tried to apply C99 mode to your C++ compiler.
LearningModern CodeNetworkingOpen SourceStorageToolsDeveloper TypeEmbedded SystemsGame DevMediaTechnical, Enterprise, HPCWebOSAll ToolsAndroid*HTML5Linux*OS X*Windows*ResourcesCode SamplesContact SupportDocumentationFree SoftwareIntel Registration CenterProduct ForumsSDKsResourcesPartner with https://software.intel.com/en-us/forums/intel-c-compiler/topic/517951 IntelAcademic ProgramPartner SpotlightBlack Belt DeveloperDeveloper MeshInnovator ProgramSuccess StoriesLearnBlogBusiness TipsEventsVideosSupportContact SupportDeveloper EvangelistsFAQsForums Search form Search You are hereHome › https://en.wikipedia.org/wiki/Restrict Forums › Intel® Software Development Products › Intel® C++ Compiler FacebookLinkedInTwitterDiggDeliciousGoogle Plus "restrict" or "__restrict" ? "restrict" or "__restrict" gcc restrict ? Inge H. Thu, 07/10/2014 - 00:48 I'm compiling a C++ program with Intel C++ Compiler XE 14.0 using the /Qrestrict compiler flag with Microsoft Visual Studio Ultimate 2013 Update 1. Unfortunetly, the compiler does not recognize the "restrict" gcc restrict error keyword - and only recognizes "__restrict". All the examples I find online uses "restrict" which makes we think that I'm doing something wrong . /MP /GS /Qrestrict /W3 /Zc:wchar_t /I"..\OptimizedStdLibFunctions" /I"..\InternalExceptions" /I"..\Worker" /I"..\SolutionDefines" /I"..\StringUtilities" /ZI /Od /Fd"Debug\vc120.pdb" /fp:strict /D "_WINSOCKAPI_" /D "NOMINMAX" /D "DEBUG" /D "NOPCH" /D "_UNICODE" /D "UNICODE" /D "_WINDOWS" /D "WIN32" /D "_DEBUG" /D "_LIB" /Zc:forScope /RTC1 /Gd /MTd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\Durability.pch" RSS Top 18 posts / 0 new Last post For more complete information about compiler optimizations, see our Optimization Notice. Log in to post comments shenghong-geng (Intel) Thu, 07/10/2014 - 01:21 "restrict" should work as documented. From my testing, it works well: C:\
is a keyword that can be used in pointer declarations. The restrict keyword is a declaration of intent given by the programmer to the compiler. It says that for the lifetime of the pointer, only the pointer itself or a value directly derived from it (such as pointer + 1) will be used to access the object to which it points. This limits the effects of pointer aliasing, aiding optimizations. If the declaration of intent is not followed and the object is accessed by an independent pointer, this will result in undefined behavior. The use of the restrict keyword in C, in principle, allows non-obtuse C to achieve the same performance as the same program written in Fortran.[1] C++ does not have standard support for restrict, but many compilers have equivalents that usually work in both C++ and C, such as the GNU Compiler Collection's and Clang's __restrict__, and Visual C++'s __restrict and __declspec(restrict). Optimization[edit] If the compiler knows that there is only one pointer to a memory block, it can produce better optimized code. For instance: void updatePtrs(size_t *ptrA, size_t *ptrB, size_t *val) { *ptrA += *val; *ptrB += *val; } In the above code, the pointers ptrA, ptrB, and val might refer to the same memory location, so the compiler may generate less optimal code: load R1 ← *val ; Load the value of val pointer load R2 ← *ptrA ; Load the value of ptrA pointer add R2 += R1 ; Perform Addition set R2 → *ptrA ; Update the value of ptrA pointer ; Similarly for ptrB, note that val is loaded twice, because ; ptrA may be equal to val (i.e., point to the same location). load R1 ← *val load R2 ← *ptrB add R2 += R1 set R2 → *ptrB However, if the restrict keyword is used and the above function is declared as void updatePtrs(size_t *restrict ptrA, size_t *restrict ptrB, size_t *restrict val); then the compiler is allowed to assume that ptrA, ptrB, and val point to different locations and updating one pointer will not affect the other pointers. The programmer, not the compiler, is responsible for ensuring that the pointers do not point to identical locations. Now the compiler can generate better code as follows: load R1 ← *val load R2 ← *ptrA add R2 += R1 set R2 → *ptrA ; Note that val is not reloaded, ; because the compiler knows it is unchanged load R2 ← *ptrB add R2 += R1 set R2 → *ptrB Note that the above assembly code is shorter be