[lug] An unusual C construct

Kenneth D Weinert kenw at quarter-flash.com
Thu Jul 29 00:07:19 MDT 2010


On 07/28/2010 11:46 PM, David Morris wrote:
> On Wed, Jul 28, 2010 at 22:57, Kenneth D Weinert<kenw at quarter-flash.com>  wrote:

>> It's nothing I need to change - I'd just like to understand how it works :)
>
> The reason this works (If I recall correctly) is that "sizeof" is an
> operator which is calculated at compile time.

Yep, that part I knew - I wasn't concerned about actually dereferencing 
the pointer at run time.

> Yes it looks weird to
> be apparently dereferencing a NULL pointer, but that code is never
> actually executed...when the code runs, that entire statement has
> already been changed to the size of acHealth_Service_Id within that
> structure.  Basically it is the (ugly) C equivalent of the C++
> statement "sizeof(tCLAIM_tbl_def::acHealth_Service_Id)".

It's just not clear to me how the compiler "does the right thing". I'm 
presuming it's some sort of idiom that just works because it does :)

It's always interesting when you start a new job and see a new body of 
code and try to understand how other people think.

Thanks for discussion.
-- 
Ken Weinert



More information about the LUG mailing list