#pragma nowarn Changes program execution

I use a bit of #pragma nowarn to stop the compiler giving me warnings about subscripts being out of range in a templated kernel (the subscripts can never be out of range but the compiler isn’t recognising that).

Today I found a bug in the kernel which was fixed by removing the #pragma nowarn commands. Rather unexpectedly this preprocessor which I was expecting just to remove annoying warnings seemed to be changing the program execution.

Is #pragma nowarn supported?

One year later and I thought I’d check if this is still a problem. It is.

Linux 64, 190.18, Toolkit 2.3. Using #pragma nowarn supresses the (incorrect) warning messages, and also breaks the program.

Without a code example that reproduces the problem, no one can even try to fix your problem…

You don’t mention what warning message (Edit: sorry, it’s the first thing you say! :)), why it’s incorrect, how you produce it… what do you seriously expect?

I don’t have CUDA available right now but the code is something like:

template<int length> kernel(...) {

	double cache[length];

	// Do some clever stuff that fills the cache

	switch (length) {

		case 1:

			a = cache[0]; break;

		case 2:

			a = cache[0] + cache[1]; break; // Gives a warning when compiled with length = 1. To supress the warning (subscript out of range) we can prepend the line with #pragma nowarn, but this appears to effect the program execution.

	}

}

#pragma Preprocessor Directives Issues special commands to the compiler. The pragma directive is used to access compiler-specific preprocessor extensions. A common use of #pragma is the #pragma once directive, which asks the compiler to include a header file only a single time, no matter how many times it has been imported.
#pragma once
// header file code

http://www.techcrashcourse.com/2015/06/c-programming-preprocessor-directives.html
http://www.techcrashcourse.com/2015/06/c-programming-header-files.html