piCookie
piCookie

Reputation: 9820

How do I inhibit "note C6311" in Microsoft C compiler?

In this maximally clipped source example, the manifest constant FOOBAR is being redefined. This is deliberate, and there is extra code in the live case to make use of each definition.

The pragma was added to get rid of a warning message, but then a note appeared, and I don't seem to find a way to get rid of the note.

I've been able to modify this particular source to #undef between the #define, but I would like to know if there's a way to inhibit the note without requiring #undef, since there are multiple constants being handled the same way.

#pragma warning( disable : 4005 ) // 'identifier' : macro redefinition
#define FOOBAR FOO
#define FOOBAR BAR

The compiler banner and output are as follows

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

message.c
message.c(3) : note C6311: message.c(2) : see previous definition of 'FOOBAR'

Upvotes: 1

Views: 701

Answers (1)

James McNellis
James McNellis

Reputation: 355207

You are not allowed to redefine a macro unless the new definition is identical to the current definition (if you redefine a macro and the new definition is different than the current definition, the program is actually ill-formed).

#undefing the macro before redefining it is the correct thing to do in this case:

#undef FOOBAR
#define FOOBAR FOO


#undef FOOBAR
#define FOOBAR BAR

Note that you are allowed to use #undef even if a macro name isn't currently defined, so there's no reason to test whether the macro is defined using #ifdef before using #undef on it.

Upvotes: 6

Related Questions