From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 435 invoked by alias); 29 Dec 2002 14:06:52 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 425 invoked from network); 29 Dec 2002 14:06:51 -0000 Received: from unknown (HELO mx12.arcor-online.net) (151.189.8.88) by 209.249.29.67 with SMTP; 29 Dec 2002 14:06:51 -0000 Received: from SERVER (otdial-212-144-106-013.arcor-ip.net [212.144.106.13]) by mx12.arcor-online.net (Postfix) with SMTP id 078D85BB6 for ; Sun, 29 Dec 2002 15:06:38 +0100 (CET) Message-ID: <002c01c2af43$7a034720$fe78a8c0@SERVER> From: "Norman Jonas" To: Subject: Re: Re: c++ "with" keyword Date: Sun, 29 Dec 2002 08:32:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-SW-Source: 2002-12/txt/msg01534.txt.bz2 I think you missed the point. The reason for the with keyword is not to use a pointer but to leave the long structs name which is not done by your example : struct S { char* name; char* street; char* city; } verylongdescriptivename; If you want to access several values of this struct you always have to type in the whole name : verylongdescriptivename.name = "hans"; verylongdescriptivename.street = "xxx 13"; verylongdescriptivename.city = "cologne"; using the "with" keyword this code becomes much smaller and cleaner : with ( verylongdescriptivename ) { .name = "hans"; .street = "xxx 13"; .city = "cologne"; } ( It is possible to use a pointer with a very short, undescriptive name, but that makes the code unreadable and stupid ( variables should have explanative names, not a confusing x* ) Norman > erik wrote : > > The example > > struct S > { > int x; > int y; > }; > > int main() > { > S s; > with (s) > { > .x = 1; > .y = 2; > } > return 0; > } > > can easily be rewritten by introducing temporary references, as in > > int main() > { > S s; > { > S& t = s; > t.x = 1; > t.y = 2; > } > return 0; > } > > This requires only one additional variable reference each time the > "with" object is used. Additionally, it allows several "with" objects > (with different names) at the same time. In C, the same thing can be > done by using pointers. > > -erik