From mboxrd@z Thu Jan 1 00:00:00 1970 From: _z33 Subject: Re: any compelling reasons to use "offsetof"? Date: Fri, 19 Aug 2005 11:16:44 +0530 Message-ID: References: Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-c-programming-owner@vger.kernel.org List-Id: Content-Type: text/plain; charset="us-ascii"; format="flowed" To: linux-c-programming@vger.kernel.org Robert P. J. Day wrote: > in a legacy project i just inherited, i did a quick recursive grep > and noticed a number of invocations of "offsetof". from experience, > i've concluded that the majority of these calls are because of sloppy > programming or laziness or just plain doing something incredibly hacky > that could be done in a more straightforward way. > > are there any really compelling reasons to need to know the offset > of a structure field? just curious. > I don't much about that macro. Anyway I came across a couple of articles from which I have a vague idea of why it is used. Mostly, if the project is of ANSI standard, then it is just there for standards compliance. Otherwise, the macro is used for the reasons mentioned here in this article . _z33 -- I love TUX; well... that's an understatement :)