Re: Faulting on dereferencing NULL (was Re: Style Question - Checking for Poor Parameters)

From: James Dow Allen (jdallen2000_at_yahoo.com)
Date: 12/01/03


Date: 30 Nov 2003 20:50:13 -0800


"xarax" <xarax@email.com> wrote in message news:<kGnyb.20275$n56.12549@newsread1.news.pas.earthlink.net>...
> "Kelsey Bjarnason" <kelseyb@lightspeed.bc.ca> wrote in message
> news:pan.2003.11.30.01.24.43.403168@lightspeed.bc.ca...
> > On Wed, 26 Nov 2003 04:12:34 -0500, Michael B Allen wrote:
> > > Not necessarily. Dereferecing NULL is going to fault on the spot.
> It depends on the target platform and how the compiler implements

FWIW, Unix on some (DEC?) machines, IIRC, stored 0 at location 0.
Thus, the code
         if (p == NULL || *p == 0)
               return FAILURE;
could be "optimized" to just
         if (*p == 0)
               return FAILURE;

(In a vaguely similar vein, Data General machines had special addresses
where *p automatically became (*p)++ or (*p)--, and special pointers
where *p automatically became **p.)

Don't blame any of this on me, please; I'm just reporting
historical trivia.

James



Relevant Pages

  • Re: Benchmarking C compilers for embedded systems
    ... Neither code size nor stack space usage is, by any reasonable stretch of the imagination, a property of any given compiler. ... It's a property of the particular chosen combination of of test code, target platform, compiler, and selected optimization options. ... In real-world applications, practical reasons drive a rather strong correlation between two main pillars of that construction: code to be run, and target hardware. ...
    (comp.arch.embedded)
  • Re: overloading in C
    ... >Jacob and his compiler along the vein of "He cannot provide even ... compiler that doesn't make an effort to comply with any known C standard, ... even when hit the user hits it over the head with requests to not use ...
    (comp.lang.c)
  • Re: Lisp w/out GC
    ... > Its a royal pain to develop and debug on your target platform. ... I am actually developing on a system with 256MB of RAM and a 700MHz ... > Lisp, suitable for your real-time requirements, complete with a compiler. ...
    (comp.lang.lisp)
  • RE: Type Mismatch error in eVC++ with BSTR type
    ... - Target platform. ... - More complete repro case. ... Interface of your ActiveX control. ... Microsoft Windows CE Compiler Team ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Code Review - is this code shit
    ... platform(the default is the host platform). ... Note that you also need the headers and libraries for the target platform; ... these are the same files you would use if you were running the compiler on ... The compiler doesn't care whether the machine code it ...
    (comp.lang.c)