Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!crdgw1!rls From: rls@onondaga.steinmetz.ge.com (Rod Sprattling) Newsgroups: comp.std.c++ Subject: Re: null references & dereferencing null pointers Message-ID: Date: 31 Jul 90 17:54:58 GMT References: <56159@microsoft.UUCP> Sender: news@crdgw1.crd.ge.com Distribution: usa Organization: General Electric CRD, Schenectady, NY Lines: 53 In-reply-to: jimad@microsoft.UUCP's message of 30 Jul 90 17:50:21 GMT One use for dereferencing null pointers leaps to mind. Consider this definition, used in Intrinsics-based widgets in the X Window System: Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts, and the Massachusetts Institute of Technology, Cambridge, Massachusetts. All Rights Reserved. #define XtOffset(type,field) \ ((unsigned int) (((char *) (&(((type)NULL)->field))) - \ ((char *) NULL))) It's used to calculate offsets into the elements of a struct, as in this snippet from a fictional wristWatch widget: static XtResource Resources[] = { { XtNwatchFaceColor, XtCFaceColor, XtRString, sizeof(char *), XtOffset(GIWristWatchWidget, watch.face_color), XtRImmediate, "White" }, .... Can anyone else think of a situation where null dereferencing is useful, besides compile-time calculation of offsets? Rod -- --------------------------------------------------------------------- __ __ |__)(__' Don't worry about not seeing the top.... | \___) _ o -_ -\> -_<\ -_ -_ ...so much as seeing the bottom. Roderick Sprattling DialCom: 8*833-7054 sprattlingrl@crd.ge.com rls@onondaga.crd.ge.com uunet!crd.ge.com!sprattlingrl ---------------------------------------------------------------------