220 7562 <CAArVCkTy7YeWPRg7=OfKZ=G+WCVbxazp6rut7+gUxS_Zd4Tx_w@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Philipp Stephani <p.stephani2@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Fixing the private method issue
Date: Mon, 4 Nov 2013 02:44:45 +0100
Lines: 278
Approved: news@gmane.org
Message-ID: <CAArVCkTy7YeWPRg7=OfKZ=G+WCVbxazp6rut7+gUxS_Zd4Tx_w@mail.gmail.com>
References: <d5cd9fa5-ac2f-465b-b92d-cf2a35607245@isocpp.org>
	<8d5f90be-ed45-4b42-9ddd-d6e2497c8166@isocpp.org>
	<CAPBZbvzB7PX9z=yRc_zG05hzeqZtUPAX6tVUT_DPdZ0ZXGXgww@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c23c8883a5ce04ea500f02
X-Trace: ger.gmane.org 1383529481 25775 80.91.229.3 (4 Nov 2013 01:44:41 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 4 Nov 2013 01:44:41 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD35NAXJW4GBBDXY3OJQKGQENIW552Q@isocpp.org Mon Nov 04 02:44:48 2013
Return-path: <std-proposals+bncBD35NAXJW4GBBDXY3OJQKGQENIW552Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f197.google.com ([209.85.212.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD35NAXJW4GBBDXY3OJQKGQENIW552Q@isocpp.org>)
	id 1Vd9Dj-0006J9-Ly
	for gclcip-std-proposals@m.gmane.org; Mon, 04 Nov 2013 02:44:47 +0100
Original-Received: by mail-wi0-f197.google.com with SMTP id f4sf4630842wiw.4
        for <gclcip-std-proposals@m.gmane.org>; Sun, 03 Nov 2013 17:44:47 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=3fYKhK0El6ATOwQjXkGBiXMNmawcTIsGXVxksvl5R0w=;
        b=BG1CzpGZEmFWQzSzMckDXvqoDYDwpj2YKuBcH1KsIFAWo+8Cjsb3whnJFIDUnv9yu5
         /94dVLU5yqe/nSnR6ssJfkq6GEm4L7TCVOWRwFKTASvneNrJ9qkfOCNE9UrvqNzOXNXo
         Ugwb75jDcbDULRNS1ARvz1B8BkZbg8cUxaZDCLTZ//47ZwxUtBTlqe7TnDwPzoB7hCRz
         NIAWBArmSGis/wguC1/8tKgy89KRxNsQMKGW3w+IoQ9nFu15ZSzr2VHbkw5wbCcc3CH5
         jFfWbk/knlQx4y+iVKNFJ+FDR+3Y1K5mobwwYC2VMksUrojRofwCaMXAQkhGoeetRiHT
         HjyA==
X-Gm-Message-State: ALoCoQkg/KIA1N/7i5iVuIIqiHtVZ69TwdPKRCyJJacrqtgIHDu9a4+skbowXPAAFVnTOr//b6wH
X-Received: by 10.180.90.196 with SMTP id by4mr5388861wib.2.1383529486959;
        Sun, 03 Nov 2013 17:44:46 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.218.130 with SMTP id pg2ls406379wic.41.canary; Sun, 03 Nov
 2013 17:44:46 -0800 (PST)
X-Received: by 10.205.15.72 with SMTP id pt8mr7714564bkb.17.1383529486035;
        Sun, 03 Nov 2013 17:44:46 -0800 (PST)
Original-Received: from mail-lb0-x236.google.com (mail-lb0-x236.google.com [2a00:1450:4010:c04::236])
        by mx.google.com with ESMTPS id yh8si2466728bkb.232.2013.11.03.17.44.45
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 03 Nov 2013 17:44:46 -0800 (PST)
Received-SPF: pass (google.com: domain of p.stephani2@gmail.com designates 2a00:1450:4010:c04::236 as permitted sender) client-ip=2a00:1450:4010:c04::236;
Original-Received: by mail-lb0-f182.google.com with SMTP id w6so4918021lbh.41
        for <std-proposals@isocpp.org>; Sun, 03 Nov 2013 17:44:45 -0800 (PST)
X-Received: by 10.112.168.170 with SMTP id zx10mr9494120lbb.0.1383529485410;
 Sun, 03 Nov 2013 17:44:45 -0800 (PST)
Original-Received: by 10.112.9.235 with HTTP; Sun, 3 Nov 2013 17:44:45 -0800 (PST)
In-Reply-To: <CAPBZbvzB7PX9z=yRc_zG05hzeqZtUPAX6tVUT_DPdZ0ZXGXgww@mail.gmail.com>
X-Original-Sender: p.stephani2@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of p.stephani2@gmail.com designates 2a00:1450:4010:c04::236 as
 permitted sender) smtp.mail=p.stephani2@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:7562
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7562>

--001a11c23c8883a5ce04ea500f02
Content-Type: text/plain; charset=ISO-8859-1

Adding a virtual member functions to a class without other virtual member
functions does change the class layout. (I guess classes whose virtual
member functions are all private don't occur in practice though.)


2013/11/4 Billy O'Neal <billy.oneal@gmail.com>

> Private member *data* does need to be declared in the class definition so
> that callers know what size to lay out for the object. Private member
> *functions* do not.
>
> Billy O'Neal
> https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
> http://stackoverflow.com/users/82320/billy-oneal
> Malware Response Instructor - BleepingComputer.com
>
>
> On Sun, Nov 3, 2013 at 1:39 PM, <shadowdrak@gmail.com> wrote:
>
>> Maybe not intuitive, but this is by design. For performance reasons, the
>> compiler needs to know the layout of a struct, and it can only do that if
>> the definition is visible. Any workarounds require an indirection AFAIK, as
>> does implementing this as standard behavior. If you want hiding and abi
>> compatibility use the PIMPL idiom for private data. But realize that it
>> adds an extra indirection.
>>
>> -Tim
>>
>>
>> On Wednesday, October 30, 2013 4:39:17 AM UTC+1, fmatth...@gmail.comwrote:
>>>
>>> There is one major wart in C++ class design, and that is with private
>>> member functions required to be in the class definition.
>>>
>>> This has a number of problems:
>>> 1) Changing the private method's signature or adding/removing private
>>> methods requires everyone including the header to recompile. This is a huge
>>> problem for large projects with long recompilation times.
>>> 2) file static / anonymous namespace definitions in the .cc file cannot
>>> be used in the private method's signature. Anything used in the signature
>>> must be at least forward declared in the header, adding more symbol
>>> pollution.
>>> 3) For shared library interfaces, the private methods are extra
>>> unnecessary symbols that have to be managed.
>>> 4) Private method signatures or even the existence of private methods
>>> can depend on the underlying implementation. If the class has multiple
>>> implementations (e.g. different platforms), #defines and other conditional
>>> compilation mechanisms are required in the header file.
>>> 5) Its just bad encapsulation. Callers don't need to know anything about
>>> the functions which implement the class behavior.
>>>
>>> The only private declarations that should be required in the header are
>>> declarations required by the compiler. I believe all of those are:
>>> 1) Private data members (sizeof())
>>> 2) Private virtual methods (for inheriting)
>>> 3) Private non-virtual methods called by inline functions.
>>>
>>> One way to do this would be to extend the friend feature. We could
>>> define friend functions within the body of member functions. It might look
>>> like this:
>>>
>>> //foo.hh
>>>
>>> class Foo {
>>>   public:
>>>     void doWork();
>>>   private:
>>>     int _f;
>>> }
>>>
>>> //foo.cc
>>> static void doWorkHelper(Foo* f) {
>>>   doSomethingWith(f->_f);
>>> };
>>>
>>> void Foo::doWork() {
>>>   friend void doWorkHelper(Foo*);
>>>
>>>   doWorkHelper(this);
>>> }
>>>
>>> This has potential for abuse of course, but it would finally allow us to
>>> limit the list of declarations in the class definition to the bare minimum
>>> required by the compiler. When it comes to defining interfaces, less is
>>> always more.
>>> One other use of this feature could be to add a backdoor for unit tests.
>>>
>>> Thoughts?
>>>
>>  --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> Visit this group at
>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c23c8883a5ce04ea500f02
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Adding a virtual member functions to a class without other=
 virtual member functions does change the class layout. (I guess classes wh=
ose virtual member functions are all private don&#39;t occur in practice th=
ough.)<br>
<div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">2013/11/4 Bil=
ly O&#39;Neal <span dir=3D"ltr">&lt;<a href=3D"mailto:billy.oneal@gmail.com=
" target=3D"_blank">billy.oneal@gmail.com</a>&gt;</span><br><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex">
<div dir=3D"ltr">Private member *data* does need to be declared in the clas=
s definition so that callers know what size to lay out for the object. Priv=
ate member *functions* do not.</div><div class=3D"gmail_extra"><div class=
=3D"im">
<br clear=3D"all">

<div><div dir=3D"ltr"><div>Billy O&#39;Neal</div><div><a href=3D"https://bi=
tbucket.org/BillyONeal/" target=3D"_blank">https://github.com/BillyONeal/</=
a></div><div><a href=3D"http://stackoverflow.com/users/82320/billy-oneal" t=
arget=3D"_blank">http://stackoverflow.com/users/82320/billy-oneal</a></div>


<div>Malware Response Instructor - BleepingComputer.com</div></div></div>
<br><br></div><div><div class=3D"h5"><div class=3D"gmail_quote">On Sun, Nov=
 3, 2013 at 1:39 PM,  <span dir=3D"ltr">&lt;<a href=3D"mailto:shadowdrak@gm=
ail.com" target=3D"_blank">shadowdrak@gmail.com</a>&gt;</span> wrote:<br><b=
lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px =
#ccc solid;padding-left:1ex">


<div dir=3D"ltr">Maybe not intuitive, but this is by design. For performanc=
e reasons, the compiler needs to know the layout of a struct, and it can on=
ly do that if the definition is visible. Any workarounds require an indirec=
tion AFAIK, as does implementing this as standard behavior. If you want hid=
ing and abi compatibility use the PIMPL idiom for private data. But realize=
 that it adds an extra indirection.<div>


<div><br></div><div>-Tim<div><div><br><br>On Wednesday, October 30, 2013 4:=
39:17 AM UTC+1, <a href=3D"mailto:fmatth...@gmail.com" target=3D"_blank">fm=
atth...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"marg=
in:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);bo=
rder-left-width:1px;border-left-style:solid">


<div dir=3D"ltr">There is one major wart in C++ class design, and that is w=
ith private member functions required to be in the class definition.<div><b=
r></div><div>This has a number of problems:</div><div>1) Changing the priva=
te method&#39;s signature or adding/removing private methods requires every=
one including the header to recompile. This is a huge problem for large pro=
jects with long recompilation times.</div>


<div>2) file static / anonymous namespace definitions in the .cc file canno=
t be used in the private method&#39;s signature. Anything used in the signa=
ture must be at least forward declared in the header, adding more symbol po=
llution.</div>


<div>3) For shared library interfaces, the private methods are extra unnece=
ssary symbols that have to be managed.</div><div>4) Private method signatur=
es or even the existence of private methods can depend on the underlying im=
plementation. If the class has multiple implementations (e.g. different pla=
tforms), #defines and other conditional compilation mechanisms are required=
 in the header file.</div>


<div>5) Its just bad encapsulation. Callers don&#39;t need to know anything=
 about the functions which implement the class behavior.</div><div><br></di=
v><div>The only private declarations that should be required in the header =
are declarations required by the compiler. I believe all of those are:</div=
>


<div>1) Private data members (sizeof())</div><div>2) Private virtual method=
s (for inheriting)</div><div>3) Private non-virtual methods called by inlin=
e functions.</div><div><br></div><div>One way to do this would be to extend=
 the friend feature. We could define friend functions within the body of me=
mber functions. It might look like this:</div>


<div><br></div><div>//foo.hh</div><div><br></div><div>class Foo {<br>=A0 pu=
blic:</div><div>=A0 =A0 void doWork();</div><div>=A0 private:</div><div>=A0=
 =A0 int _f;</div><div>}</div><div><br></div><div>//foo.cc</div><div>static=
 void doWorkHelper(Foo* f) {</div>


<div>=A0 doSomethingWith(f-&gt;_f);<br>};</div><div><br></div><div>void Foo=
::doWork() {<br>=A0 friend void doWorkHelper(Foo*);</div><div><br></div><di=
v>=A0 doWorkHelper(this);</div><div>}</div><div><br></div><div>This has pot=
ential for abuse of course, but it would finally allow us to limit the list=
 of declarations in the class definition to the bare minimum required by th=
e compiler. When it comes to defining interfaces, less is always more.</div=
>


<div>One other use of this feature could be to add a backdoor for unit test=
s.</div><div><br></div><div>Thoughts?</div></div></blockquote></div></div><=
/div></div></div><div><div>

<p></p>

-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div></div></div><div class=3D"HOEnZb">=
<div class=3D"h5">

<p></p>

-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c23c8883a5ce04ea500f02--

.
