[Exceptional C++ Style] Re: [Exception C++ Style] Item 15 - UsesandAbuses of Access Rights

Kevlin Henney kevlin at curbralan.com
Tue Dec 14 11:21:53 EST 2004


In message <005e01c4e1e8$fd60d360$6700a8c0 at myopwv.com>, Paul Grenyer 
<paul at paulgrenyer.co.uk> writes
>
>> > The Pickpocket attempts to change the meaning of the
>> > class definition by redefining private as public:
>> >
>> > #define private public
>> >
>> > However, the above is illegal as it attempts to
>> > redefine a keyword. It also breaks the ODR and
>> > therefore the same thing applies as was stated
>>
>> A lighter version of this pickpocket would use
>>
>> #define private friend class MyClass; private
>> #include "x.h"
>> #undef private
>>
>> That IMHO leaves less chance for the compiler to break anything -- and if
>> done everywhere not even breaks the ODR.  As the #define for is considered
>> harmless this should be similar.
>
>I'm shocked! Why are you even contemplating this? Sure it's just plain evil?

I'm impressed, this is a nice refinement. And yes, it is evil. <cue evil 
laughter>

In fact it is the ability to shock that is part of the power of these 
techniques. Nearly ten years ago I used the "#define private public" as 
a blunt instrument in some inter-company politics. I never had to wield 
it, just threaten it.

An integration team that had a central (bucket of a) header required by 
all participating development teams from different companies refused to 
update a class that had a feature I needed for the proof-of-concept test 
that we had to run. The function was private and the integration manager 
said he would make it public on Tuesday; we needed it on the Thursday 
before (IIRC, it was just before Easter weekend). Both annoyingly and 
ironically it was the integration team for whom the proof-of-concept was 
being run. I had not come across the "#define private public" anywhere, 
but it sprang to mind as a solution and as something that might shock 
the delicate sensibilities of the integration manager and motivate him 
to do something. It had the desired effect: his jaw dropped as he gasped 
"you... can't do... that... can you?" I nodded. He changed the file.

 >:->

Kevlin
-- 
____________________________________________________________

   Kevlin Henney                   phone:  +44 117 942 2990
   mailto:kevlin at curbralan.com     mobile: +44 7801 073 508
   http://www.curbralan.com        fax:    +44 870 052 2289
   Curbralan: Consultancy + Training + Development + Review
____________________________________________________________



More information about the Effective-cpp mailing list