[vtk-developers] VTK style ques. - enum vars
David Gobbi
david_gobbi at rogers.com
Mon Sep 18 10:07:00 EDT 2006
Hi Dean,
I don't think that enums can be #undef'd, but it
certainly is true that a #define will overrule an enum.
Here is an example:
[in the widget header file...]
enum { LEFT_BUTTON = 1 };
[and then in a header file included in the widget .cxx file...]
#define LEFT_BUTTON 0
The problem is that, after the preprocessor has seen the
#define statement, it will replace every instance of
LEFT_BUTTON with 0. Preprocessing occurs before
compilation, so the compiler proper will never even see
LEFT_BUTTON.
In other words, just because an enum is a member of
a class or namespace, that doesn't protect it from being
silently overruled by a #define.
So, definitely, enum constant names should prefixed
with "VTK" in order to protect them from conflicts.
- David
----- Original Message ----
From: Dean Inglis <dean.inglis at sympatico.ca>
To: vtk-developers at vtk.org
Sent: Monday, September 18, 2006 9:39:05 AM
Subject: [vtk-developers] VTK style ques. - enum vars
with regard to this vtkusers message thread:
http://public.kitware.com/pipermail/vtkusers/2006-September/087016.html
it appears that at least 1 user has experienced
this problem with a conflict between #defines of
LEFT_BUTTON, RIGHT_BUTTON, MIDDLE_BUTTON
in the MFC afxctl.h file and the (protected) enum vars
in vtkImagePlaneWidget.h:
enum
{
LEFT_BUTTON = 1,
RIGHT_BUTTON = 2,
MIDDLE_BUTTON = 3
};
It was news to me that enums within a class are treated as
#defines and can therefore be #undef(ined) (please correct
me if I'm wrong!). As a question of style, is there any
objection/problem to changing the above enums to say
enum
{
VTK_LEFT_BUTTON = 1,
VTK_RIGHT_BUTTON = 2,
VTK_MIDDLE_BUTTON = 3
};
thanks,
Dean
_______________________________________________
vtk-developers mailing list
vtk-developers at vtk.org
http://www.vtk.org/mailman/listinfo/vtk-developers
More information about the vtk-developers
mailing list