warning: ’sqlstm’ defined but not used

At my current job, I had the misfortune of having to deal with some Oracle Pro*C code. Since I’m a -Werror weenie, I was annoyed that this code was spitting out a ‘warning: ’sqlstm’ defined but not used’ warning in all the proc generated source. Here’s how I inhibited the warning.

I added a new pc_common.h file

// If you know a better way to avoid the 'sqlstm' defined but not used warning, I tip my hat to you.
#define AVOID_THE_UNUSED_SQLSTM_WARNING(X) void avoid_the_sqlstm_defined_but_unused_warning_for_ ## X () { sqlstm = sqlstm; }

Then in some sample.pc that’s generating the warning:

#ifndef ORA_PROC
	#include "pc_common.h"
AVOID_THE_UNUSED_SQLSTM_WARNING(sample)
#endif

The problem is that the generated proc code includes a static struct named ’sqlstm’, but then the generated code never references this struct. Instead it uses a local sqlstm variable whenever it’s used elsewhere in the generateed code.

The workaround adds a hopefully-unused function to the source that uses the static sqlstm struct. This is enough for the compiler to mark it as being used, even though the function itself is never used.

However, I did have to introduce the argument to the macro to force a unique name for these functions, since the linker will complain about there being multiple functions with the same signature in in different files.

Leave a Reply

You must be logged in to post a comment.